From 9d43f8f049c0f13bd5b0080ef64f3e624922b365 Mon Sep 17 00:00:00 2001 From: tsteven4 Date: Wed, 11 Jul 2018 16:56:20 -0600 Subject: [PATCH] refactor "Declarator and assignment can be joined." (#227) * refactor "Delarator and assignment can be joined." Instances involving switch statements or goto statemens were skipped. jeeps was skipped as well. * fix pointer formatting case. * more whitespace corrections. --- alan.cc | 130 +++++++++++------------------- an1.cc | 53 ++++--------- arcdist.cc | 14 ++-- bcr.cc | 60 +++++--------- bend.cc | 3 +- brauniger_iq.cc | 3 +- bushnell.cc | 21 ++--- bushnell_trl.cc | 10 +-- cet.cc | 54 ++++++------- cet_util.cc | 34 +++----- compegps.cc | 27 +++---- cst.cc | 14 ++-- csv_util.cc | 41 +++------- defs.h | 3 +- delgpl.cc | 9 +-- destinator.cc | 50 +++++------- dg-100.cc | 59 ++++++-------- dmtlog.cc | 66 +++++---------- duplicate.cc | 13 ++- easygps.cc | 10 +-- energympro.cc | 6 +- exif.cc | 118 ++++++++++----------------- explorist_ini.cc | 3 +- f90g_track.cc | 6 +- filter_vecs.cc | 35 +++----- g7towin.cc | 27 +++---- garmin.cc | 53 +++++-------- garmin_device_xml.cc | 3 +- garmin_fit.cc | 23 ++---- garmin_fs.cc | 16 ++-- garmin_gpi.cc | 70 ++++++---------- garmin_tables.cc | 13 +-- garmin_txt.cc | 128 +++++++++++------------------- garmin_xt.cc | 30 +++---- gbfile.cc | 56 ++++--------- gbser.cc | 9 +-- gbser_win.cc | 18 ++--- gdb.cc | 115 ++++++++++----------------- geojson.cc | 3 +- ggv_bin.cc | 34 +++----- ggv_log.cc | 44 ++++------ ggv_ovl.cc | 41 ++++------ globalsat_sport.cc | 35 +++----- gnav_trl.cc | 3 +- gopal.cc | 37 ++++----- gpssim.cc | 13 ++- gpsutil.cc | 25 +++--- gpx.cc | 76 ++++++------------ grtcirc.cc | 36 ++++----- gtm.cc | 6 +- height.cc | 19 ++--- hiketech.cc | 3 +- holux.cc | 25 +++--- html.cc | 6 +- humminbird.cc | 97 ++++++++--------------- igc.cc | 44 ++++------ igo8.cc | 9 +-- inifile.cc | 20 ++--- interpolate.cc | 18 ++--- itracku.cc | 37 +++------ jtr.cc | 21 +++-- kml.cc | 36 +++------ lmx.cc | 7 +- lowranceusr.cc | 65 ++++++--------- lowranceusr4.cc | 100 ++++++++++------------- maggeo.cc | 31 +++----- magproto.cc | 114 ++++++++++---------------- main.cc | 4 +- mapasia.cc | 16 ++-- mapsend.cc | 32 +++----- mapsource.cc | 86 +++++++------------- mkshort.cc | 21 ++--- mmo.cc | 167 +++++++++++++------------------------- mtk_locus.cc | 72 +++++------------ mtk_logger.cc | 122 ++++++++++++++-------------- navicache.cc | 3 +- naviguide.cc | 16 ++-- navilink.cc | 60 +++++--------- navitel.cc | 18 ++--- netstumbler.cc | 20 +++-- nmea.cc | 55 +++++-------- nmn4.cc | 19 ++--- osm.cc | 19 ++--- ozi.cc | 6 +- parse.cc | 5 +- pcx.cc | 14 ++-- pocketfms_bc.cc | 6 +- pocketfms_wp.cc | 6 +- polygon.cc | 12 +-- position.cc | 6 +- psitrex.cc | 19 ++--- queue.h | 23 +++--- random.cc | 18 ++--- raymarine.cc | 39 +++------ reverse_route.cc | 4 +- rgbcolors.cc | 3 +- route.cc | 30 +++---- saroute.cc | 56 +++++-------- sbn.cc | 20 ++--- sbp.cc | 3 +- session.cc | 4 +- shape.cc | 18 ++--- skyforce.cc | 28 +++---- skytraq.cc | 95 +++++++++------------- smplrout.cc | 6 +- stackfilter.cc | 3 +- stmsdf.cc | 11 +-- stmwpp.cc | 9 +-- subrip.cc | 12 ++- swapdata.cc | 3 +- tef_xml.cc | 6 +- text.cc | 7 +- tiger.cc | 12 +-- tmpro.cc | 9 +-- tomtom.cc | 7 +- tpg.cc | 20 ++--- tpo.cc | 185 ++++++++++++++----------------------------- trackfilter.cc | 85 ++++++++------------ transform.cc | 4 +- unicsv.cc | 32 +++----- util.cc | 132 ++++++++++++------------------ v900.cc | 17 ++-- vcf.cc | 21 ++--- vecs.cc | 9 +-- vpl.cc | 3 +- waypt.cc | 39 ++++----- wbt-200.cc | 87 +++++++------------- wintec_tes.cc | 3 +- xcsv.cc | 6 +- xmlgeneric.cc | 3 +- xmltag.cc | 4 +- 131 files changed, 1525 insertions(+), 2763 deletions(-) diff --git a/alan.cc b/alan.cc index 4f5fdc92c..449607891 100644 --- a/alan.cc +++ b/alan.cc @@ -198,11 +198,9 @@ static arglist_t trl_args[] = { static unsigned int byte_order() { unsigned long test = BYTEORDER_TEST; - unsigned char* ptr; - unsigned int order; - ptr = (unsigned char*)(&test); - order = (ptr[0] << 12) | (ptr[1] << 8) | (ptr[2] << 4) | ptr[3]; + unsigned char* ptr = (unsigned char*)(&test); + unsigned int order = (ptr[0] << 12) | (ptr[1] << 8) | (ptr[2] << 4) | ptr[3]; return order; } @@ -413,9 +411,7 @@ static void trl_swap(struct trldata* trldata) static void str2lab(char* dest, const char* src, int len, const char* fmt, int n) { - int j; - - j = 0; + int j = 0; if (src != nullptr) { for (int i=0; itm_mday | ((tm->tm_mon+1)<<8) | ((tm->tm_year+1900)<<16); *time = t % 86400; } static time_t unpack_time(int32_t date, int32_t time) { - time_t result; - short year, month, day; static int m_to_d[12] = {0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334}; - year = (date >> 16) & 0xffff; - month = (date >> 8) & 0xff; /* 1-12 */ - day = date & 0xff; /* 1-31 */ + short year = (date >> 16) & 0xffff; + short month = (date >> 8) & 0xff; /* 1-12 */ + short day = date & 0xff; /* 1-31 */ month -= 1; /* fit struct tm */ year += month / 12; @@ -465,7 +457,7 @@ static time_t unpack_time(int32_t date, int32_t time) year -= 1; month += 12; } - result = (year - 1970) * 365 + m_to_d[month]; + time_t result = (year - 1970) * 365 + m_to_d[month]; if (month <= 1) { year -= 1; } @@ -484,20 +476,17 @@ static time_t unpack_time(int32_t date, int32_t time) static Waypoint* get_wpt(struct wprdata* wprdata, unsigned n) { - struct wpthdr* wpthdr; - struct wpt* wpt; - int j, idx; - Waypoint* WP; + int j; - wpthdr = &(wprdata->wpthdr); - idx = wpthdr->idx[n]; + struct wpthdr* wpthdr = &(wprdata->wpthdr); + int idx = wpthdr->idx[n]; if (idx == WPT_IDX_NONE || wpthdr->used[idx] == WPT_UNUSED) { return nullptr; } - wpt = &(wprdata->wpt[idx]); + struct wpt* wpt = &(wprdata->wpt[idx]); - WP = new Waypoint; + Waypoint* WP = new Waypoint; WP->latitude = -pt2deg(wpt->pt.y); WP->longitude = pt2deg(wpt->pt.x); WP->SetCreationTime(unpack_time(wpt->date, wpt->time)); @@ -521,11 +510,8 @@ static Waypoint* get_wpt(struct wprdata* wprdata, unsigned n) static void wpr_read() { struct wprdata wprdata; - struct rtehdr* rtehdr; - struct rte* rte; - int i, j, idx; + int i, j; Waypoint* WP; - route_head* RT; if (gbfread(&wprdata, sizeof(struct wprdata), 1, fin) != 1) { fatal(MYNAME ": Read error on '%s'. Perhaps this isn't an alan file\n", fin->name); @@ -545,15 +531,15 @@ static void wpr_read() } /* routes */ - rtehdr = &(wprdata.rtehdr); + struct rtehdr* rtehdr = &(wprdata.rtehdr); for (i=0; iidx[i]; + int idx = rtehdr->idx[i]; if (idx == RTE_IDX_NONE || rtehdr->used[idx] == RTE_UNUSED) { continue; } - rte = &(wprdata.rte[idx]); + struct rte* rte = &(wprdata.rte[idx]); - RT = route_head_alloc(); + route_head* RT = route_head_alloc(); RT->rte_num = i; for (j=RTE_NAME_LEN-1; j >= 0 && rte->name[j] == ' '; j--) {}; char *s = xstrndup(rte->name,j+1); @@ -583,10 +569,6 @@ static void wpr_read() static void trl_read() { struct trldata trldata; - struct trkhdr* trkhdr; - struct trklog* trklog; - Waypoint* WP; - route_head* TL; int i, j; for (i=0; ioccupied == TRK_UNUSED) { continue; } - TL = route_head_alloc(); + route_head* TL = route_head_alloc(); for (j=TRK_NAME_LEN-1; j >= 0 && (trkhdr->name[j] == ' ' || trkhdr->name[j] == '\0'); j--) {}; @@ -630,9 +612,9 @@ static void trl_read() track_add_head(TL); /* track points */ - trklog = &(trldata.trklog[i]); + struct trklog* trklog = &(trldata.trklog[i]); for (j=0; jtotalpt; j++) { - WP = new Waypoint; + Waypoint* WP = new Waypoint; WP->latitude = -pt2deg(trklog->pt[j].y); WP->longitude = pt2deg(trklog->pt[j].x); WP->altitude = hgt2m(trklog->sh[j].height); @@ -650,16 +632,15 @@ static void trl_read() static int find_wpt(struct wprdata* wprdata, const Waypoint* WP) { - struct wpt pattern, *wpt; - int wpt_idx; + struct wpt pattern; str2lab(pattern.name, WP->shortname, WPT_NAME_LEN, nullptr, 0); pattern.pt.x = deg2pt(WP->longitude); pattern.pt.y = deg2pt(-WP->latitude); - wpt = wprdata->wpt; + struct wpt* wpt = wprdata->wpt; for (int i = 0; iwpthdr.idx[i]; + int wpt_idx = wprdata->wpthdr.idx[i]; if (wpt_idx == WPT_IDX_NONE || wprdata->wpthdr.used[wpt_idx] == WPT_UNUSED) { continue; @@ -676,14 +657,12 @@ static int find_wpt(struct wprdata* wprdata, const Waypoint* WP) static int add_wpt(struct wprdata* wprdata, const Waypoint* WP,int isroute) { - struct wpthdr* wpthdr; - int hdr_idx, wpt_idx; struct wpt* wpt; int i; - wpthdr = &(wprdata->wpthdr); + struct wpthdr* wpthdr = &(wprdata->wpthdr); - hdr_idx = find_wpt(wprdata, WP); + int hdr_idx = find_wpt(wprdata, WP); if (hdr_idx >= 0) { /* duplicate waypoint */ if (isroute) { @@ -696,7 +675,7 @@ static int add_wpt(struct wprdata* wprdata, const Waypoint* WP,int isroute) for (i=0; iidx[i] != WPT_IDX_NONE; i++) { } hdr_idx = i; for (i=0; iused[i] != WPT_UNUSED; i++) { } - wpt_idx = i; + int wpt_idx = i; if (wpthdr->num >= MAXWPT || hdr_idx >= MAXWPT || wpt_idx >= MAXWPT) { fatal(MYNAME ": Can't store more than %u waypoints\n", MAXWPT); } @@ -729,21 +708,18 @@ static void wpr_waypoint(const Waypoint* WP) static void wpr_route_hdr(const route_head* RT) { - struct rtehdr* rtehdr; - int hdr_idx, rte_idx; - struct rte* rte; int i; - rtehdr = &(WPR.rtehdr); + struct rtehdr* rtehdr = &(WPR.rtehdr); for (i=0; iidx[i] != RTE_IDX_NONE; i++) { } - hdr_idx = i; + int hdr_idx = i; for (i=0; iused[i] != RTE_UNUSED; i++) { } - rte_idx = i; + int rte_idx = i; if (rtehdr->num >= MAXRTE || hdr_idx >= MAXRTE || rte_idx >= MAXRTE) { fatal(MYNAME ": Can't store more than %u routes", MAXRTE); } - rte = &(WPR.rte[rte_idx]); + struct rte* rte = &(WPR.rte[rte_idx]); str2lab(rte->name, RT->rte_name, RTE_NAME_LEN, "R%03d", rte_idx); str2lab(rte->comment, RT->rte_desc, RTE_COMMENT_LEN, nullptr, 0); pack_time(time(nullptr), &(rte->date), &(rte->time)); @@ -762,15 +738,12 @@ static void wpr_route_hdr(const route_head* RT) static void wpr_route_wpt(const Waypoint* WP) { - struct rte* rte; - int wpt_idx; - - rte = &(WPR.rte[WPR.rtehdr.num -1]); + struct rte* rte = &(WPR.rte[WPR.rtehdr.num -1]); if (rte->wptnum >= MAXWPTINRTE) { fatal(MYNAME ": Can't store more than %u waypoints per route", MAXWPTINRTE); } - wpt_idx = add_wpt(&WPR, WP, 1); + int wpt_idx = add_wpt(&WPR, WP, 1); rte->wptidx[rte->wptnum] = wpt_idx; rte->wptnum ++; @@ -814,10 +787,9 @@ static void wpr_write() static void trl_track_hdr(const route_head* TL) { - struct trkhdr* trkhdr; - int idx, l; + int idx; - trkhdr = TRL.loghdr.trkhdr; + struct trkhdr* trkhdr = TRL.loghdr.trkhdr; for (idx=0; idx< MAXTRK && trkhdr[idx].occupied != TRK_UNUSED; idx++) {}; if (idx >= MAXTRK) { @@ -834,7 +806,7 @@ static void trl_track_hdr(const route_head* TL) if (TL->rte_desc != nullptr) { strncpy(trkhdr[idx].comment, CSTRc(TL->rte_desc), TRK_COMMENT_LEN); - l = strlen(CSTRc(TL->rte_desc)); + int l = strlen(CSTRc(TL->rte_desc)); if (l < TRK_COMMENT_LEN-1) { memset(trkhdr[idx].comment + l, ' ', TRK_COMMENT_LEN - l); } @@ -851,19 +823,15 @@ static void trl_track_hdr(const route_head* TL) static void trl_track_wpt(const Waypoint* WP) { - struct trklog* trklog; - struct trkhdr* trkhdr; - int trk_idx, log_idx; + int trk_idx = TRL.loghdr.num; - trk_idx = TRL.loghdr.num; - - trkhdr = &(TRL.loghdr.trkhdr[trk_idx]); + struct trkhdr* trkhdr = &(TRL.loghdr.trkhdr[trk_idx]); if (trkhdr->totalpt >= MAXPTINTRK) { fatal(MYNAME ": Can't store more than %u points per track", MAXPTINTRK); } - log_idx = trkhdr->next; + int log_idx = trkhdr->next; - trklog = &(TRL.trklog[trk_idx]); + struct trklog* trklog = &(TRL.trklog[trk_idx]); trklog->pt[log_idx].x = deg2pt(WP->longitude); trklog->pt[log_idx].y = deg2pt(-WP->latitude); if WAYPT_HAS(WP, speed) { @@ -879,11 +847,8 @@ static void trl_track_wpt(const Waypoint* WP) static void trl_track_tlr(const route_head*) { - struct trkhdr* trkhdr; - int trk_idx; - - trk_idx = TRL.loghdr.num; - trkhdr = &(TRL.loghdr.trkhdr[trk_idx]); + int trk_idx = TRL.loghdr.num; + struct trkhdr* trkhdr = &(TRL.loghdr.trkhdr[trk_idx]); if (trkhdr->totalpt == 0) { trkhdr->occupied = TRK_UNUSED; @@ -894,16 +859,13 @@ static void trl_track_tlr(const route_head*) static void trl_write() { - struct trkhdr* trkhdr; - void* buf; int i; - size_t fill; TRL.loghdr.id = TRL_HDR_ID; TRL.loghdr.num = TRL.loghdr.next = -1; TRL.loghdr.date = TRL.loghdr.time = 0; for (i=0; itotalpt = 0; trkhdr->next = 0; memset(trkhdr->name, 0, TRK_NAME_LEN); @@ -919,8 +881,8 @@ static void trl_write() trl_swap(&TRL); - fill = 0x10000 - 2 * sizeof(struct trklog); - buf = xmalloc(fill); + size_t fill = 0x10000 - 2 * sizeof(struct trklog); + void* buf = xmalloc(fill); if (buf == nullptr) { fatal(MYNAME ": Not enough memory\n"); } diff --git a/an1.cc b/an1.cc index 23ae46492..a3d29010b 100644 --- a/an1.cc +++ b/an1.cc @@ -351,8 +351,6 @@ static void Destroy_AN1_Symbol(an1_symbol_record* symbol) static void Read_AN1_Waypoint(gbfile* f, an1_waypoint_record* wpt) { - unsigned short len; - wpt->magic = ReadShort(f); wpt->unk1 = ReadLong(f); wpt->lon = ReadLong(f); @@ -368,7 +366,7 @@ static void Read_AN1_Waypoint(gbfile* f, an1_waypoint_record* wpt) wpt->visible_zoom = ReadChar(f); wpt->unk5 = ReadShort(f); wpt->radius = ReadDouble(f); - len = ReadShort(f); + unsigned short len = ReadShort(f); wpt->name = ReadString(f, len); if (len != strlen(wpt->name)) { @@ -382,13 +380,12 @@ static void Read_AN1_Waypoint(gbfile* f, an1_waypoint_record* wpt) ofs += 2; if (len) { - char* oldurlstr; /* * Trust URL encoded in new format over one in * old format if both are present. Whack the * name starting at '{URL='. */ - oldurlstr = strstr(wpt->name, "{URL="); + char* oldurlstr = strstr(wpt->name, "{URL="); if (oldurlstr) { *oldurlstr = 0; } @@ -541,16 +538,13 @@ static void Write_AN1_Vertex(gbfile* f, an1_vertex_record* vertex) static void Read_AN1_Line(gbfile* f, an1_line_record* line) { - - short len; - line->roadtype = ReadLong(f); line->serial = ReadShort(f); line->unk2 = ReadLong(f); line->unk3 = ReadShort(f); line->type = ReadShort(f); line->unk4 = ReadLong(f); - len = ReadShort(f); + short len = ReadShort(f); line->name = ReadString(f, len); line->lineweight = ReadShort(f); line->linestyle = ReadLong(f); @@ -565,15 +559,13 @@ static void Read_AN1_Line(gbfile* f, an1_line_record* line) static void Write_AN1_Line(gbfile* f, an1_line_record* line) { - short len; - WriteLong(f, line->roadtype); WriteShort(f, line->serial); WriteLong(f, line->unk2); WriteShort(f, line->unk3); WriteShort(f, line->type); WriteLong(f, line->unk4); - len = strlen(line->name); + short len = strlen(line->name); WriteShort(f, len); WriteString(f, line->name); WriteShort(f, (short) line->lineweight); @@ -594,45 +586,35 @@ static void Skip_AN1_IL(gbfile* f) static void Skip_AN1_BM(gbfile* f) { - unsigned long bmsize; - unsigned long palettesize; - unsigned long bmisize; - unsigned long bitoffset; - Skip(f, 8); /* BITMAPFILEHEADER fields 1-3 */ - bitoffset = ReadLong(f); + unsigned long bitoffset = ReadLong(f); - bmisize = ReadLong(f); + unsigned long bmisize = ReadLong(f); Skip(f, 16); /* BITMAPINFOHEADER fields 2-6 */ - bmsize = ReadLong(f); + unsigned long bmsize = ReadLong(f); Skip(f, 16); /* BITMAPINFOHEADER fields 8-11 */ - palettesize = bitoffset - bmisize - 14; + unsigned long palettesize = bitoffset - bmisize - 14; Skip(f, bmsize + palettesize); } static void Read_AN1_Symbol(gbfile* f, an1_symbol_record* symbol) { - short len; - /* This is just the high word of a long; we ate the low * word in the caller. Fortunately, we don't care. */ symbol->hotspotxhi = ReadShort(f); symbol->hotspoty = ReadLong(f); symbol->unk1 = ReadLong(f); ReadGuid(f, &symbol->guid); - len = ReadChar(f); + short len = ReadChar(f); symbol->name = ReadString(f, len); } static void Read_AN1_Header(gbfile* f) { - unsigned short magic; - unsigned short type; - - magic = ReadShort(f); + unsigned short magic = ReadShort(f); (void) magic; // hush warning. - type = ReadShort(f); + unsigned short type = ReadShort(f); last_read_type = type; } @@ -645,10 +627,9 @@ static void Write_AN1_Header(gbfile* f) static void Read_AN1_Bitmaps(gbfile* f) { - long count; an1_symbol_record symbol; - count = ReadLong(f); + long count = ReadLong(f); while (count) { unsigned short magic = ReadShort(f); @@ -679,14 +660,13 @@ static void Write_AN1_Bitmaps(gbfile* f) static void Read_AN1_Waypoints(gbfile* f) { - Waypoint* wpt_tmp; char* icon = nullptr; ReadShort(f); unsigned long count = ReadLong(f); for (unsigned long i = 0; i < count; i++) { an1_waypoint_record* rec = Alloc_AN1_Waypoint(); Read_AN1_Waypoint(f, rec); - wpt_tmp = new Waypoint; + Waypoint* wpt_tmp = new Waypoint; if (rec->creation_time) { wpt_tmp->SetCreationTime(rec->creation_time); @@ -824,16 +804,13 @@ static void Write_AN1_Waypoints(gbfile* f) static void Read_AN1_Lines(gbfile* f) { - route_head* rte_head; - Waypoint* wpt_tmp; - ReadShort(f); unsigned long count = ReadLong(f); for (unsigned long i = 0; i < count; i++) { an1_line_record* rec = Alloc_AN1_Line(); Read_AN1_Line(f, rec); /* create route rec */ - rte_head = route_head_alloc(); + route_head* rte_head = route_head_alloc(); rte_head->line_color.bbggrr = rec->linecolor; if (rec->opacity == 0x8200) { rte_head->line_color.opacity = 128; @@ -852,7 +829,7 @@ static void Read_AN1_Lines(gbfile* f) Read_AN1_Vertex(f, vert); /* create route point */ - wpt_tmp = new Waypoint; + Waypoint* wpt_tmp = new Waypoint; wpt_tmp->latitude = DecodeOrd(vert->lat); wpt_tmp->longitude = -DecodeOrd(vert->lon); wpt_tmp->shortname = QString().sprintf("\\%5.5lx", rtserial++); diff --git a/arcdist.cc b/arcdist.cc index 86145fcd5..91e1688a7 100644 --- a/arcdist.cc +++ b/arcdist.cc @@ -109,18 +109,15 @@ void ArcDistanceFilter::process() RteHdFunctor arcdist_arc_disp_hdr_cb_f(this, &ArcDistanceFilter::arcdist_arc_disp_hdr_cb); queue* elem, * tmp; - unsigned removed; if (arcfileopt) { int fileline = 0; char* line; - gbfile* file_in; - Waypoint* arcpt2, * arcpt1; - file_in = gbfopen(arcfileopt, "r", MYNAME); + gbfile* file_in = gbfopen(arcfileopt, "r", MYNAME); - arcpt1 = new Waypoint; - arcpt2 = new Waypoint; + Waypoint* arcpt1 = new Waypoint; + Waypoint* arcpt2 = new Waypoint; arcdist_arc_disp_hdr_cb(nullptr); arcpt2->latitude = arcpt2->longitude = BADVAL; @@ -157,15 +154,14 @@ void ArcDistanceFilter::process() track_disp_all(arcdist_arc_disp_hdr_cb_f, nullptr, arcdist_arc_disp_wpt_cb_f); } - removed = 0; + unsigned removed = 0; #if NEWQ foreach (Waypoint* wp, waypt_list) { #else QUEUE_FOR_EACH(&waypt_head, elem, tmp) { Waypoint* wp = (Waypoint*) elem; #endif - extra_data* ed; - ed = (extra_data*) wp->extra_data; + extra_data* ed = (extra_data*) wp->extra_data; wp->extra_data = nullptr; if (ed) { if ((ed->distance >= pos_dist) == (exclopt == nullptr)) { diff --git a/bcr.cc b/bcr.cc index 39a63cab4..02b1d6224 100644 --- a/bcr.cc +++ b/bcr.cc @@ -126,14 +126,10 @@ bcr_icon_mapping_t bcr_icon_mapping[] = { static void bcr_handle_icon_str(const char* str, Waypoint* wpt) { - bcr_icon_mapping_t* m; - wpt->icon_descr = BCR_DEF_MPS_ICON; - for (m = bcr_icon_mapping; (m->bcr_name); m++) { + for (bcr_icon_mapping_t* m = bcr_icon_mapping; (m->bcr_name); m++) { if (case_ignore_strcmp(str, m->bcr_name) == 0) { - int nr; - if (m->symbol_DE == nullptr) { if (! m->warned) { m->warned = true; @@ -143,7 +139,7 @@ bcr_handle_icon_str(const char* str, Waypoint* wpt) } wpt->description = m->symbol_DE; if (m->mps_name != nullptr) { - nr = gt_find_icon_number_from_desc(m->mps_name, MAPSOURCE); + int nr = gt_find_icon_number_from_desc(m->mps_name, MAPSOURCE); wpt->icon_descr = gt_find_desc_from_icon_number(nr, MAPSOURCE); } return; @@ -157,9 +153,7 @@ get_bcr_icon_from_icon_descr(const QString& icon_descr) const char* result = BCR_DEF_ICON; if (!icon_descr.isNull()) { - bcr_icon_mapping_t* m; - - for (m = bcr_icon_mapping; (m->bcr_name); m++) { + for (bcr_icon_mapping_t* m = bcr_icon_mapping; (m->bcr_name); m++) { if (! m->mps_name) { continue; } @@ -210,11 +204,10 @@ bcr_rd_deinit() static void bcr_create_waypts_from_route(route_head* route) { - Waypoint* wpt; queue* elem, *tmp; QUEUE_FOR_EACH(&route->waypoint_list, elem, tmp) { - wpt = new Waypoint(*(Waypoint*) elem); + Waypoint* wpt = new Waypoint(*(Waypoint*) elem); waypt_add(wpt); } } @@ -222,10 +215,8 @@ bcr_create_waypts_from_route(route_head* route) static void bcr_wgs84_to_mercator(const double lat, const double lon, int* north, int* east) { - double N, E; - - N = log(tan(lat * M_PI / 360 + M_PI / 4)) * radius; - E = lon * radius * M_PI / 180.0; + double N = log(tan(lat * M_PI / 360 + M_PI / 4)) * radius; + double E = lon * radius * M_PI / 180.0; if (lat > 0) { N += 0.500000000001; /* we go from double to integer */ @@ -254,11 +245,9 @@ bcr_mercator_to_wgs84(const int north, const int east, double* lat, double* lon) static void bcr_data_read() { - int index; char* str; - route_head* route; - route = route_head_alloc(); + route_head* route = route_head_alloc(); if ((str = inifile_readstr(ini, "client", "routename"))) { route->rte_name = str; @@ -266,12 +255,11 @@ bcr_data_read() route_add_head(route); - for (index = 1; index > 0; index ++) { + for (int index = 1; index > 0; index ++) { char station[32]; char* str; int mlat, mlon; /* mercator data */ - Waypoint* wpt; snprintf(station, sizeof(station), "STATION%d", index); if (nullptr == (str = inifile_readstr(ini, "coordinates", station))) { @@ -282,15 +270,13 @@ bcr_data_read() fatal(MYNAME ": structure error at %s (Coordinates)!\n", station); } - wpt = new Waypoint; + Waypoint* wpt = new Waypoint; wpt->shortname = station; bcr_mercator_to_wgs84(mlat, mlon, &wpt->latitude, &wpt->longitude); if (nullptr != (str = inifile_readstr(ini, "client", station))) { - char* cx; - - cx = strchr(str, ','); + char* cx = strchr(str, ','); if (cx == nullptr) { fatal(MYNAME ": structure error at %s (Client)!\n", station); } @@ -299,9 +285,7 @@ bcr_data_read() } if (nullptr != (str = inifile_readstr(ini, "description", station))) { - char* c; - - c = strchr(str, ','); + char* c = strchr(str, ','); if (c != nullptr) { *c = '\0'; } @@ -362,9 +346,7 @@ static void bcr_write_line(gbfile* fout, const QString& key, int* index, const Q /* so we respectfully add a CR/LF on each line */ gbfprintf(fout, "%s\r\n", CSTR(key)); } else { - char* tmp; - - tmp = (value != nullptr) ? xstrdup(value) : xstrdup(""); + char* tmp = (value != nullptr) ? xstrdup(value) : xstrdup(""); if (index != nullptr) { gbfprintf(fout, "%s%d=%s\r\n", CSTR(key), *index, tmp); } else { @@ -379,8 +361,7 @@ bcr_route_header(const route_head* route) { queue* elem, *tmp; Waypoint* wpt; - QString sout; - int i, north, east, nmin, nmax, emin, emax; + int north, east, nmax, emin; curr_rte_num++; if (curr_rte_num != target_rte_num) { @@ -390,7 +371,7 @@ bcr_route_header(const route_head* route) bcr_write_line(fout, "[CLIENT]", nullptr, nullptr); /* client section */ bcr_write_line(fout, "REQUEST", nullptr, "TRUE"); - sout = route->rte_name; + QString sout = route->rte_name; if (rtename_opt != nullptr) { sout = rtename_opt; } @@ -402,14 +383,13 @@ bcr_route_header(const route_head* route) bcr_write_line(fout, "DESCRIPTIONLINES", nullptr, "0"); - i = 0; + int i = 0; QUEUE_FOR_EACH(&route->waypoint_list, elem, tmp) { - const char* icon; Waypoint* wpt = (Waypoint*) elem; i++; - icon = get_bcr_icon_from_icon_descr(wpt->icon_descr); + const char* icon = get_bcr_icon_from_icon_descr(wpt->icon_descr); sout = QString("%1,%2").arg(icon).arg(BCR_UNKNOWN,10); bcr_write_line(fout, "STATION", &i, sout); @@ -417,8 +397,8 @@ bcr_route_header(const route_head* route) bcr_write_line(fout, "[COORDINATES]", nullptr, nullptr); /* coords section */ - nmin = emin = (1<<30); - emax = nmax = -nmin; + int nmin = emin = (1<<30); + int emax = nmax = -nmin; i = 0; QUEUE_FOR_EACH(&route->waypoint_list, elem, tmp) { @@ -448,11 +428,11 @@ bcr_route_header(const route_head* route) i = 0; QUEUE_FOR_EACH(&route->waypoint_list, elem, tmp) { - QString s1, s2; + QString s2; i++; wpt = (Waypoint*) elem; - s1 = wpt->notes; + QString s1 = wpt->notes; if (s1.isEmpty()) { s1 = wpt->description; } diff --git a/bend.cc b/bend.cc index d66525f49..f70f392b9 100644 --- a/bend.cc +++ b/bend.cc @@ -53,7 +53,6 @@ Waypoint* BendFilter::create_wpt_dest(const Waypoint* wpt_orig, double lat_orig, { double distance = gcdist(lat_orig, long_orig, lat_orig_adj, long_orig_adj); - double frac; double lat_dest; double long_dest; distance = radtometers(distance); @@ -61,7 +60,7 @@ Waypoint* BendFilter::create_wpt_dest(const Waypoint* wpt_orig, double lat_orig, return nullptr; } - frac = maxDist / distance; + double frac = maxDist / distance; linepart(lat_orig, long_orig, lat_orig_adj, long_orig_adj, frac, &lat_dest, &long_dest); diff --git a/brauniger_iq.cc b/brauniger_iq.cc index 606344b1a..bb400a435 100644 --- a/brauniger_iq.cc +++ b/brauniger_iq.cc @@ -232,7 +232,6 @@ static int process_data(const unsigned char* data) static void data_read() { unsigned char ibuf[25]; - int rd_cnt; if (global_opts.debug_level >= 0) { puts(MYNAME ": Select recorded flight in memo mode."); @@ -248,7 +247,7 @@ static void data_read() state = st_sync; for (;;) { /* wait up to 5 seconds for more data */ - rd_cnt = gbser_read_wait(serial_handle, ibuf, reqd_bytes[state], 5000); + int rd_cnt = gbser_read_wait(serial_handle, ibuf, reqd_bytes[state], 5000); if (rd_cnt < 0) { fatal(MYNAME ": Serial error\n"); } else if (rd_cnt < reqd_bytes[state]) { diff --git a/bushnell.cc b/bushnell.cc index f6e424375..a150ad85c 100644 --- a/bushnell.cc +++ b/bushnell.cc @@ -130,13 +130,11 @@ static icon_mapping_t bushnell_icons[] = { static unsigned int bushnell_get_icon_from_name(QString name) { - icon_mapping_t* t; - if (name.isNull()) { name = "Waypoint"; } - for (t = bushnell_icons; t->icon != nullptr; t++) { + for (icon_mapping_t* t = bushnell_icons; t->icon != nullptr; t++) { if (0 == name.compare(t->icon, Qt::CaseInsensitive)) { return t->symbol; } @@ -147,8 +145,7 @@ bushnell_get_icon_from_name(QString name) static const char* bushnell_get_name_from_symbol(signed int s) { - icon_mapping_t* t; - for (t = bushnell_icons; t->icon != nullptr; t++) { + for (icon_mapping_t* t = bushnell_icons; t->icon != nullptr; t++) { if (s == t->symbol) { return t->icon; } @@ -201,17 +198,14 @@ wr_deinit() static void bushnell_read() { - int32_t lat_tmp,lon_tmp; - unsigned int proximity; - unsigned int icon; Waypoint* wpt_tmp = new Waypoint; - lat_tmp = gbfgetint32(file_in); - lon_tmp = gbfgetint32(file_in); + int32_t lat_tmp = gbfgetint32(file_in); + int32_t lon_tmp = gbfgetint32(file_in); - icon = gbfgetc(file_in); + unsigned int icon = gbfgetc(file_in); wpt_tmp->icon_descr = bushnell_get_name_from_symbol(icon); - proximity = gbfgetc(file_in); // 1 = off, 3 = proximity alarm. + unsigned int proximity = gbfgetc(file_in); // 1 = off, 3 = proximity alarm. (void) proximity; wpt_tmp->latitude = lat_tmp / 10000000.0; wpt_tmp->longitude = lon_tmp / 10000000.0; @@ -228,14 +222,13 @@ bushnell_write_one(const Waypoint* wpt) { char tbuf[20]; // 19 text bytes + null terminator. char padding[2] = {0, 0}; - gbfile* file_out; static int wpt_count; QString fname(ofname); fname += "-"; fname += QString::number(wpt_count++); fname += ".wpt"; - file_out = gbfopen_le(fname, "wb", MYNAME); + gbfile* file_out = gbfopen_le(fname, "wb", MYNAME); gbfputint32(round(wpt->latitude * 10000000), file_out); gbfputint32(round(wpt->longitude * 10000000), file_out); gbfputc(bushnell_get_icon_from_name(wpt->icon_descr), file_out); diff --git a/bushnell_trl.cc b/bushnell_trl.cc index db723e379..56961475d 100644 --- a/bushnell_trl.cc +++ b/bushnell_trl.cc @@ -95,19 +95,15 @@ wr_deinit() static void bushnell_read() { - int lat_tmp,lon_tmp; - while (true) { - Waypoint* wpt_tmp; - - lat_tmp = gbfgetint32(file_in); - lon_tmp = gbfgetint32(file_in); + int lat_tmp = gbfgetint32(file_in); + int lon_tmp = gbfgetint32(file_in); if (!lat_tmp && !lon_tmp) { break; } - wpt_tmp = new Waypoint; + Waypoint* wpt_tmp = new Waypoint; wpt_tmp->latitude = lat_tmp / 10000000.0; wpt_tmp->longitude = lon_tmp / 10000000.0; diff --git a/cet.cc b/cet.cc index 9b2821f6a..97e47ad5e 100644 --- a/cet.cc +++ b/cet.cc @@ -37,11 +37,10 @@ int cet_char_to_ucs4(const char src, const cet_cs_vec_t* vec, int* value) { - int trash, c; - int* dest; + int trash; - c = ((unsigned char)src & 0xFF); - dest = (value != nullptr) ? value : &trash; + int c = ((unsigned char)src & 0xFF); + int* dest = (value != nullptr) ? value : &trash; *dest = c; c -= vec->ucs4_offset; @@ -69,9 +68,8 @@ cet_ucs4_to_utf8(char* dest, size_t dest_size, int value) { int result; unsigned char trash[16]; - unsigned char* c; - c = (dest != nullptr) ? (unsigned char*) dest : trash; + unsigned char* c = (dest != nullptr) ? (unsigned char*) dest : trash; if ((value & 0xffffff80) == 0) { /* <= 7 bits */ if (dest_size < 1) { @@ -323,10 +321,10 @@ cet_utf8_strndup(const char* str, const int maxlen) { if (str) { const char* cin = str; - char* res, *cout; + char* cout; int len = 0; - res = cout = xstrdup(cin); + char* res = cout = xstrdup(cin); while (*cin && (len < maxlen)) { int bytes, value; @@ -362,9 +360,7 @@ char* cet_str_utf8_to_any(const char* src, const cet_cs_vec_t* vec) { const char* c = src; - int len; - char* res, *dest; - const char* cend; + char* dest; if (c == nullptr) { return nullptr; @@ -373,10 +369,10 @@ cet_str_utf8_to_any(const char* src, const cet_cs_vec_t* vec) return xstrdup(src); /* UTF-8 -> UTF-8 */ } - len = strlen(c); - res = dest = (char*) xmalloc(len + 1); /* target will become smaller or equal length */ + int len = strlen(c); + char* res = dest = (char*) xmalloc(len + 1); /* target will become smaller or equal length */ - cend = c + len; + const char* cend = c + len; while (c < cend) { int bytes; @@ -396,12 +392,11 @@ cet_str_utf8_to_any(const char* src, const cet_cs_vec_t* vec) char* cet_str_any_to_utf8(const char* src, const cet_cs_vec_t* vec) { - int len, value; - char* result, *cout; - const char* cin; + int value; + char* cout; char temp = CET_NOT_CONVERTABLE_DEFAULT; - cin = src; + const char* cin = src; if (cin == nullptr) { return nullptr; } @@ -409,7 +404,7 @@ cet_str_any_to_utf8(const char* src, const cet_cs_vec_t* vec) return xstrdup(src); /* UTF-8 -> UTF-8 */ } - len = 0; + int len = 0; while (*cin != '\0') { /* determine length of resulting UTF-8 string */ if (CET_ERROR == cet_char_to_ucs4(*cin++, vec, &value)) { cet_char_to_ucs4(temp, vec, &value); @@ -417,7 +412,7 @@ cet_str_any_to_utf8(const char* src, const cet_cs_vec_t* vec) len += cet_ucs4_to_utf8(nullptr, 6, value); } - result = cout = (char*) xmalloc(len + 1); + char* result = cout = (char*) xmalloc(len + 1); cin = src; while (*cin != '\0') { @@ -437,23 +432,21 @@ cet_str_any_to_utf8(const char* src, const cet_cs_vec_t* vec) char* cet_str_uni_to_utf8(const short* src, const int length) { - int i, len; - unsigned short* cin; - char* res, *cout; + char* cout; if (src == nullptr) { return nullptr; } - len = 0; - i = length; - cin = (unsigned short*)src; + int len = 0; + int i = length; + unsigned short* cin = (unsigned short*)src; while (i-- > 0) { len += cet_ucs4_to_utf8(nullptr, 6, le_read16(cin++)); } - res = cout = (char*) xmalloc(len + 1); + char* res = cout = (char*) xmalloc(len + 1); cin = (unsigned short*)src; i = length; @@ -474,8 +467,7 @@ short* cet_str_any_to_uni(const char* src, const cet_cs_vec_t* vec, int* length) { char* utf8; - int len; - short* res, *sout; + short* sout; if (! src) { utf8 = xstrdup(""); @@ -485,8 +477,8 @@ cet_str_any_to_uni(const char* src, const cet_cs_vec_t* vec, int* length) utf8 = cet_str_any_to_utf8(src, vec); } - len = cet_utf8_strlen(utf8); - res = sout = (short int*) xcalloc(2, len + 1); + int len = cet_utf8_strlen(utf8); + short* res = sout = (short int*) xcalloc(2, len + 1); if (len) { char* cin = utf8; diff --git a/cet_util.cc b/cet_util.cc index ec00e48e3..c6be77ef8 100644 --- a/cet_util.cc +++ b/cet_util.cc @@ -63,7 +63,6 @@ cet_str_utf8_to_uni(const char* src, int* length) char* cet_str_any_to_any(const char* src, const cet_cs_vec_t* src_vec, const cet_cs_vec_t* dest_vec) { - char* c0, *c1; const cet_cs_vec_t* v_in = (src_vec != nullptr) ? src_vec : &cet_cs_vec_ansi_x3_4_1968; const cet_cs_vec_t* v_out = (dest_vec != nullptr) ? dest_vec : &cet_cs_vec_ansi_x3_4_1968; @@ -73,8 +72,8 @@ cet_str_any_to_any(const char* src, const cet_cs_vec_t* src_vec, const cet_cs_ve return xstrdup(src); } - c0 = (v_in == &cet_cs_vec_utf8) ? xstrdup(src) : cet_str_any_to_utf8(src, v_in); - c1 = (v_out == &cet_cs_vec_utf8) ? xstrdup(c0) : cet_str_utf8_to_any(c0, v_out); + char* c0 = (v_in == &cet_cs_vec_utf8) ? xstrdup(src) : cet_str_any_to_utf8(src, v_in); + char* c1 = (v_out == &cet_cs_vec_utf8) ? xstrdup(c0) : cet_str_utf8_to_any(c0, v_out); xfree(c0); return c1; @@ -147,7 +146,6 @@ cet_register() if (cet_cs_vec_ct > 0) { cet_cs_vec_t* p; - cet_cs_alias_t* list; c = 0; /* enumerate count of all names and aliases */ @@ -164,7 +162,7 @@ cet_register() } /* create name to vec table */ - list = (cet_cs_alias_t*) xcalloc(c, sizeof(*list)); + cet_cs_alias_t* list = (cet_cs_alias_t*) xcalloc(c, sizeof(*list)); i = 0; for (p = cet_cs_vec_root; p != nullptr; p = p->next) { if (p->alias != nullptr) { @@ -213,24 +211,19 @@ cet_register() cet_cs_vec_t* cet_find_cs_by_name(const QString& name) { - int i, j; - cet_register(); if (cet_cs_alias == nullptr) { return nullptr; } - i = 0; - j = cet_cs_alias_ct - 1; + int i = 0; + int j = cet_cs_alias_ct - 1; while (i <= j) { - int a, x; - cet_cs_alias_t* n; - - a = (i + j) >> 1; - n = &cet_cs_alias[a]; - x = case_ignore_strcmp(name, n->name); + int a = (i + j) >> 1; + cet_cs_alias_t* n = &cet_cs_alias[a]; + int x = case_ignore_strcmp(name, n->name); if (x == 0) { return n->vec; } else if (x < 0) { @@ -266,15 +259,13 @@ cet_deregister() int cet_validate_cs(const QString& cs, cet_cs_vec_t** vec, QString* cs_name) { - cet_cs_vec_t* v; - if (cs.isEmpty()) { /* set default us-ascii */ *vec = &cet_cs_vec_ansi_x3_4_1968; *cs_name = CET_CHARSET_ASCII; return 1; } - v = cet_find_cs_by_name(cs); + cet_cs_vec_t* v = cet_find_cs_by_name(cs); if (v != nullptr) { // TODO: make v->name into q QString and replace this... char* tmp = xstrdup(v->name); @@ -363,15 +354,13 @@ cet_convert_from_utf8(const char* str) char* cet_convert_string(char* str) { - char* res; - if (str == nullptr) { return nullptr; /* return origin if empty or NULL */ } else if (*str == '\0') { return str; } - res = converter(str); + char* res = converter(str); xfree(str); return res; } @@ -391,7 +380,6 @@ static void cet_convert_waypt(const Waypoint* wpt) { Waypoint* w = const_cast(wpt); - format_specific_data* fs; if ((cet_output == 0) && (w->wpt_flags.cet_converted != 0)) { return; @@ -399,7 +387,7 @@ cet_convert_waypt(const Waypoint* wpt) w->wpt_flags.cet_converted = 1; - fs = wpt->fs; + format_specific_data* fs = wpt->fs; while (fs != nullptr) { if (fs->convert != nullptr) { fs->convert(fs); diff --git a/compegps.cc b/compegps.cc index a5eb1dac6..f0f8cd2e0 100644 --- a/compegps.cc +++ b/compegps.cc @@ -127,12 +127,11 @@ static void compegps_parse_date(const char* c, struct tm* tm) { char month[4]; - int year; tm->tm_mday = atoi(c); strncpy(month, c+3, 3); month[3] = 0; tm->tm_mon = month_lookup(month); - year = atoi(c + 7); + int year = atoi(c + 7); if (year < 70) { year += 100; } @@ -157,13 +156,13 @@ static Waypoint* parse_wpt(char* buff) { int col = -1; - char* c, *cx; + char* cx; Waypoint* wpt = new Waypoint; struct tm tm; int has_time = 0; memset(&tm, 0, sizeof(tm)); - c = strstr(buff, "A "); + char* c = strstr(buff, "A "); if (c == buff) { col++; } @@ -230,11 +229,10 @@ parse_wpt(char* buff) static void parse_wpt_info(const char* buff, Waypoint* wpt) /* "w" */ { - char* c; int col = -1; double fx; - c = csv_lineparse(buff, ",", "", col++); + char* c = csv_lineparse(buff, ",", "", col++); while (c != nullptr) { c = lrtrim(c); if (*c != '\0') { @@ -275,11 +273,10 @@ static Waypoint* parse_trkpt(char* buff) { int col = -1; - char* c; struct tm tm; Waypoint* wpt = new Waypoint; - c = strstr(buff, "A "); + char* c = strstr(buff, "A "); if (c == buff) { col++; } @@ -320,10 +317,9 @@ parse_trkpt(char* buff) static void parse_track_info(const char* buff, route_head* track) /* "t" */ { - char* c; int col = -1; - c = csv_lineparse(buff, "|", "", col++); + char* c = csv_lineparse(buff, "|", "", col++); while (c != nullptr) { c = lrtrim(c); if (*c != '\0') { @@ -349,10 +345,9 @@ parse_track_info(const char* buff, route_head* track) /* "t" */ static void parse_rte_info(const char* buff, route_head* route) /* "R" */ { - char* c; int col = -1; - c = csv_lineparse(buff, ",", "", col++); + char* c = csv_lineparse(buff, ",", "", col++); while (c != nullptr) { c = lrtrim(c); if (*c != '\0') { @@ -400,8 +395,6 @@ compegps_data_read(void) route_head* track = nullptr; while ((buff = gbfgetstr(fin))) { - char* ctail; - if ((line++ == 0) && fin->unicode) { cet_convert_init(CET_CHARSET_UTF8, 1); } @@ -410,7 +403,7 @@ compegps_data_read(void) continue; } - ctail = strchr(cin, ' '); + char* ctail = strchr(cin, ' '); if (ctail == nullptr) { continue; } @@ -478,8 +471,6 @@ compegps_data_read(void) static void write_waypt_cb(const Waypoint* wpt) { - QString name; - if (curr_index != target_index) { return; } @@ -488,7 +479,7 @@ write_waypt_cb(const Waypoint* wpt) QString cleaned_name(wpt->shortname); cleaned_name.replace(' ', '_'); - name = (snlen > 0) ? mkshort(sh, cleaned_name) : cleaned_name; + QString name = (snlen > 0) ? mkshort(sh, cleaned_name) : cleaned_name; gbfprintf(fout, "W %s A ", CSTR(name)); gbfprintf(fout, "%.10f%c%c ", diff --git a/cst.cc b/cst.cc index 3b2e12f2f..f85dc3cc8 100644 --- a/cst.cc +++ b/cst.cc @@ -76,7 +76,6 @@ static char* cst_make_url(char* str) { int len = strlen(str); - char* res; if (len < 3) { return nullptr; @@ -85,30 +84,27 @@ cst_make_url(char* str) if (strstr(str, "://") > str) { return xstrdup(str); } else if (strstr(str, ":\\") == str+1) { /* DOS 0.01++ file format */ - res = xstrdup("file://*:"); + char* res = xstrdup("file://*:"); res[7] = *str++; res[8] = *str++; res = xstrappend(res, str); { - char* c; - int i; - - c = res; /* replace all backslashes with a slash */ + char* c = res; /* replace all backslashes with a slash */ while ((c = strchr(c, '\\'))) { *c++ = '/'; } c = res; /* enumerate number of spaces within filename */ - i = 0; + int i = 0; while ((c = strchr(c, ' '))) { c++; i++; } if (i > 0) { /* .. and replace them with "%20" */ - char* src, *dest, *last; + char* src, *dest; - last = src = res; + char* last = src = res; res = dest = (char*) xcalloc(strlen(src) + (2*i) + 1, 1); while ((c = strchr(src, ' '))) { if (c != src) { diff --git a/csv_util.cc b/csv_util.cc index 4f902cb78..b01a2bcb4 100644 --- a/csv_util.cc +++ b/csv_util.cc @@ -263,12 +263,10 @@ char* csv_lineparse(const char* stringstart, const char* delimited_by, const char* enclosed_in, const int line_no) { - const char* sp; static const char* p = nullptr; static char* tmp = nullptr; size_t dlen = 0, elen = 0, efound = 0; int enclosedepth = 0; - short int dfound; short int hyper_whitespace_delimiter = 0; if (tmp) { @@ -302,7 +300,7 @@ csv_lineparse(const char* stringstart, const char* delimited_by, } /* the beginning of the string we start with (this pass) */ - sp = p; + const char* sp = p; /* length of delimiters and enclosures */ if ((delimited_by) && (!hyper_whitespace_delimiter)) { @@ -311,7 +309,7 @@ csv_lineparse(const char* stringstart, const char* delimited_by, if (enclosed_in) { elen = strlen(enclosed_in); } - dfound = 0; + short int dfound = 0; while ((*p) && (!dfound)) { if ((elen) && (strncmp(p, enclosed_in, elen) == 0)) { @@ -415,11 +413,9 @@ static double decdir_to_dec(const char* decdir) { char* p; - const char* cp; - double rval; int sign = 0; - cp = &decdir[0]; + const char* cp = &decdir[0]; if ((*cp == 'W') || (*cp == 'S')) { sign = -1; @@ -427,7 +423,7 @@ decdir_to_dec(const char* decdir) sign = 1; } - rval = sign ? strtod(&decdir[1], &p) : strtod(&decdir[0], &p); + double rval = sign ? strtod(&decdir[1], &p) : strtod(&decdir[0], &p); if (sign == 0) { if ((*p == 'W') || (*p == 'S')) { @@ -876,10 +872,9 @@ addhms(const char* s, const char* format) int hour =0; int min =0; int sec =0; - int ac; char* ampm = (char*) xmalloc(strlen(s) + 1); - ac = sscanf(s, format, &hour, &min, &sec, ampm); + int ac = sscanf(s, format, &hour, &min, &sec, ampm); /* If no time format in arg string, assume AM */ if (ac < 4) { ampm[0] = 0; @@ -1119,10 +1114,8 @@ xcsv_parse_val(const char* s, Waypoint* wpt, const field_map_t* fmp, break; /* ALTITUDE CONVERSIONS ************************************************/ case XT_ALT_FEET: { - /* altitude in feet as a decimal value */ - double val; char *endptr; - val = strtod(s, &endptr); + double val = strtod(s, &endptr); if ((val == 0 && s==endptr)) { wpt->altitude = unknown_alt; } else { @@ -1134,10 +1127,8 @@ xcsv_parse_val(const char* s, Waypoint* wpt, const field_map_t* fmp, } break; case XT_ALT_METERS: { - /* altitude in meters as a decimal value */ - double val; char *endptr; - val = strtod(s, &endptr); + double val = strtod(s, &endptr); if ((val == 0 && s==endptr)) { wpt->altitude = unknown_alt; } else { @@ -1424,11 +1415,7 @@ void xcsv_data_read(void) { char* buff = nullptr; - char* s; - Waypoint* wpt_tmp; int linecount = 0; - queue* elem; - field_map_t* fmp; route_head* rte = nullptr; route_head* trk = nullptr; utm_northing = 0; @@ -1467,9 +1454,9 @@ xcsv_data_read(void) } } if (strlen(buff)) { - wpt_tmp = new Waypoint; + Waypoint* wpt_tmp = new Waypoint; - s = buff; + char* s = buff; s = csv_lineparse(s, CSTR(xcsv_file.field_delimiter), CSTR(xcsv_file.field_encloser), linecount); @@ -1478,13 +1465,13 @@ xcsv_data_read(void) } /* reset the ifield queue */ - elem = QUEUE_FIRST(&xcsv_file.ifield); + queue* elem = QUEUE_FIRST(&xcsv_file.ifield); /* now rip the line apart, advancing the queue for each tear * off the beginning of buff since there's no index into queue. */ while (s) { - fmp = (field_map_t*) elem; + field_map_t* fmp = (field_map_t*) elem; xcsv_parse_val(s, wpt_tmp, fmp, &trk); elem = QUEUE_NEXT(elem); @@ -1576,8 +1563,6 @@ static void xcsv_waypt_pr(const Waypoint* wpt) { QString buff; - int i; - field_map_t* fmp; queue* elem, *tmp; double latitude, longitude; int32 utmz; @@ -1635,7 +1620,7 @@ xcsv_waypt_pr(const Waypoint* wpt) &latitude, &longitude, &alt, xcsv_file.gps_datum); } - i = 0; + int i = 0; QUEUE_FOR_EACH(xcsv_file.ofield, elem, tmp) { double lat = latitude; double lon = longitude; @@ -1647,7 +1632,7 @@ xcsv_waypt_pr(const Waypoint* wpt) */ int field_is_unknown = 0; - fmp = (field_map_t*) elem; + field_map_t* fmp = (field_map_t*) elem; if ((i != 0) && !(fmp->options & OPTIONS_NODELIM)) { *xcsv_file.stream << write_delimiter; diff --git a/defs.h b/defs.h index cc2c48e5b..b3e48a866 100644 --- a/defs.h +++ b/defs.h @@ -604,9 +604,8 @@ waypt_disp_session(const session_t* se, T cb) foreach (Waypoint* waypointp, waypt_list) { #else queue* elem, *tmp; - Waypoint* waypointp; QUEUE_FOR_EACH(&waypt_head, elem, tmp) { - waypointp = (Waypoint*) elem; + Waypoint* waypointp = (Waypoint*) elem; #endif if ((se == nullptr) || (waypointp->session == se)) { if (global_opts.verbose_status) { diff --git a/delgpl.cc b/delgpl.cc index 8d930a012..616971065 100644 --- a/delgpl.cc +++ b/delgpl.cc @@ -51,19 +51,16 @@ gpl_rd_init(const QString& fname) static void gpl_read() { - Waypoint* wpt_tmp; - route_head* track_head; gpl_point_t gp; - double alt_feet; - track_head = route_head_alloc(); + route_head* track_head = route_head_alloc(); track_add_head(track_head); while (gbfread(&gp, sizeof(gp), 1, gplfile_in) > 0) { - wpt_tmp = new Waypoint; + Waypoint* wpt_tmp = new Waypoint; wpt_tmp->latitude = le_read_double(&gp.lat); wpt_tmp->longitude = le_read_double(&gp.lon); - alt_feet = le_read_double(&gp.alt); + double alt_feet = le_read_double(&gp.alt); wpt_tmp->altitude = FEET_TO_METERS(alt_feet); if (wpt_tmp->altitude <= unknown_alt + 1) { wpt_tmp->altitude = unknown_alt; diff --git a/destinator.cc b/destinator.cc index 9b6586439..f6b9719ab 100644 --- a/destinator.cc +++ b/destinator.cc @@ -101,9 +101,8 @@ static void write_wcstr(const QString& str) { int len; - short* unicode; - unicode = cet_str_utf8_to_uni(CSTR(str), &len); + short* unicode = cet_str_utf8_to_uni(CSTR(str), &len); gbfwrite((void*)unicode, 2, len + 1, fout); xfree(unicode); } @@ -111,13 +110,11 @@ write_wcstr(const QString& str) static int read_until_wcstr(const char* str) { - char* buff; - int len, sz; int eos = 0, res = 0; - len = strlen(str); - sz = (len + 1) * 2; - buff = (char*) xcalloc(sz, 1); + int len = strlen(str); + int sz = (len + 1) * 2; + char* buff = (char*) xcalloc(sz, 1); while (! gbfeof(fin)) { @@ -148,14 +145,12 @@ read_until_wcstr(const char* str) static void destinator_read_poi() { - Waypoint* wpt; int count = 0; gbfrewind(fin); while (!(gbfeof(fin))) { - QString str, hnum; - double ll; + QString str; garmin_fs_t* gmsd; if (count == 0) { @@ -169,12 +164,12 @@ destinator_read_poi() count++; - wpt = new Waypoint; + Waypoint* wpt = new Waypoint; wpt->shortname = read_wcstr(0); wpt->notes = read_wcstr(0); /* comment */ - hnum = read_wcstr(0); /* house number */ + QString hnum = read_wcstr(0); /* house number */ str = read_wcstr(0); /* street */ if (str.isEmpty()) { @@ -208,7 +203,7 @@ destinator_read_poi() wpt->longitude = gbfgetdbl(fin); wpt->latitude = gbfgetdbl(fin); - ll = gbfgetdbl(fin); + double ll = gbfgetdbl(fin); if (ll != wpt->longitude) { fatal(MYNAME "_poi: Invalid file!\n"); } @@ -230,11 +225,8 @@ destinator_read_rte() gbfrewind(fin); while (!(gbfeof(fin))) { - QString str; - Waypoint* wpt; - if (count == 0) { - str = read_wcstr(0); + QString str = read_wcstr(0); if ((str != DST_ITINERARY)) { fatal(MYNAME "_itn: Invalid record header!\n"); } @@ -244,7 +236,7 @@ destinator_read_rte() count++; - wpt = new Waypoint; + Waypoint* wpt = new Waypoint; wpt->shortname = read_wcstr(0); wpt->notes = read_wcstr(0); @@ -283,10 +275,8 @@ destinator_read_trk() gbfrewind(fin); while (!(gbfeof(fin))) { - Waypoint* wpt; struct tm tm; char buff[20]; - int date; recno++; @@ -294,7 +284,7 @@ destinator_read_trk() break; } - wpt = new Waypoint; + Waypoint* wpt = new Waypoint; wpt->longitude = gbfgetdbl(fin); wpt->latitude = gbfgetdbl(fin); @@ -309,7 +299,7 @@ destinator_read_trk() gbfseek(fin, 12 * sizeof(int32_t), SEEK_CUR); /* SAT info */ - date = gbfgetint32(fin); + int date = gbfgetint32(fin); double milliseconds = gbfgetflt(fin); gbfseek(fin, 2 * 12, SEEK_CUR); /* SAT info */ @@ -343,7 +333,6 @@ destinator_read_trk() static void destinator_read() { - int i0, i1; double d0, d1; char buff[16]; @@ -351,8 +340,8 @@ destinator_read() fatal(MYNAME ": Unexpected EOF (end of file)!\n"); } - i0 = le_read32(&buff[0]); - i1 = le_read32(&buff[4]); + int i0 = le_read32(&buff[0]); + int i1 = le_read32(&buff[4]); if ((i0 == 0x690043) && (i1 == 0x790074)) { if (data_type != rtedata) { @@ -428,17 +417,14 @@ destinator_trkpt_disp(const Waypoint* wpt) } if (wpt->creation_time.isValid()) { - struct tm tm; - double milliseconds; - int date; const time_t ct = wpt->GetCreationTime().toTime_t(); - tm = *gmtime(&ct); + struct tm tm = *gmtime(&ct); tm.tm_mon += 1; tm.tm_year -= 100; - date = (tm.tm_mday * 10000) + (tm.tm_mon * 100) + tm.tm_year; + int date = (tm.tm_mday * 10000) + (tm.tm_mon * 100) + tm.tm_year; gbfputint32(date, fout); - milliseconds = (tm.tm_hour * 10000) + - (tm.tm_min * 100) + tm.tm_sec; + double milliseconds = (tm.tm_hour * 10000) + + (tm.tm_min * 100) + tm.tm_sec; milliseconds = (milliseconds * 1000) + (wpt->GetCreationTime().time().msec()); gbfputflt(milliseconds, fout); diff --git a/dg-100.cc b/dg-100.cc index 1ae6f4d36..3d7c965e5 100644 --- a/dg-100.cc +++ b/dg-100.cc @@ -324,16 +324,13 @@ static size_t dg100_send(uint8_t cmd, const void* payload, size_t param_len) { uint8_t frame[FRAME_MAXLEN]; - uint16_t checksum, payload_len; - size_t framelen; - int n; - payload_len = 1 + param_len; + uint16_t payload_len = 1 + param_len; /* Frame length calculation: * frame start sequence(2), payload length field(2), command id(1), * param(variable length), * checksum(2), frame end sequence(2) */ - framelen = 2 + 2 + 1 + param_len + 2 + 2; + size_t framelen = 2 + 2 + 1 + param_len + 2 + 2; assert(framelen <= FRAME_MAXLEN); /* create frame head + command */ @@ -345,11 +342,11 @@ dg100_send(uint8_t cmd, const void* payload, size_t param_len) memcpy(frame + 5, payload, param_len); /* create frame tail */ - checksum = dg100_checksum(frame + 4, framelen - 8); + uint16_t checksum = dg100_checksum(frame + 4, framelen - 8); be_write16(frame + framelen - 4, checksum); be_write16(frame + framelen - 2, 0xB0B3); - n = gbser_write(serial_handle, frame, framelen); + int n = gbser_write(serial_handle, frame, framelen); if (global_opts.debug_level) { struct dg100_command* cmdp = dg100_findcmd(cmd); @@ -369,11 +366,9 @@ dg100_send(uint8_t cmd, const void* payload, size_t param_len) static int dg100_recv_byte() { - int result; - /* allow for a delay of 40s; * erasing the whole DG-100 memory takes about 21s */ - result = gbser_readc_wait(serial_handle, 40000); + int result = gbser_readc_wait(serial_handle, 40000); switch (result) { case gbser_ERROR: fatal("dg100_recv_byte(): error reading one byte\n"); @@ -390,15 +385,11 @@ static int dg100_recv_frame(struct dg100_command** cmdinfo_result, uint8_t** payload) { static uint8_t buf[FRAME_MAXLEN]; - uint16_t frame_start_seq, payload_len_field; - uint16_t payload_end_seq, payload_checksum, frame_end_seq; - uint16_t frame_head, numheaders, sum; - uint8_t c, cmd; - int i, param_len, frame_len; - struct dg100_command* cmdinfo; + uint16_t payload_end_seq; + uint8_t c; /* consume input until frame head sequence 0xA0A2 was received */ - frame_head = 0; + uint16_t frame_head = 0; dg100_debug("Receiving ", 0, 0, nullptr); do { c = dg100_recv_byte(); @@ -429,14 +420,14 @@ dg100_recv_frame(struct dg100_command** cmdinfo_result, uint8_t** payload) */ /* read Payload Length, Command ID, and two further bytes */ - i = gbser_read_wait(serial_handle, &buf[2], 5, 1000); + int i = gbser_read_wait(serial_handle, &buf[2], 5, 1000); if (i < 5) { fatal("Expected to read 5 bytes, but got %d\n", i); } dg100_debug("", 0, 5, &buf[2]); - payload_len_field = be_read16(buf + 2); - cmd = buf[4]; + uint16_t payload_len_field = be_read16(buf + 2); + uint8_t cmd = buf[4]; /* * getconfig/setconfig have the same answer ID - @@ -448,21 +439,21 @@ dg100_recv_frame(struct dg100_command** cmdinfo_result, uint8_t** payload) cmd = dg100cmd_setconfig; } - cmdinfo = dg100_findcmd(cmd); + struct dg100_command* cmdinfo = dg100_findcmd(cmd); if (!cmdinfo) { /* TODO: consume data until frame end signature, * then report failure to the caller? */ fatal("unknown answer ID %02x\n", cmd); } - param_len = cmdinfo->recvsize; + int param_len = cmdinfo->recvsize; /* * the getfileheader answer has a varying param_len, * we need to calculate it */ if (cmd == dg100cmd_getfileheader) { - numheaders = be_read16(buf + 5); + uint16_t numheaders = be_read16(buf + 5); param_len = 2 + 2 + 12 * numheaders; } @@ -474,7 +465,7 @@ dg100_recv_frame(struct dg100_command** cmdinfo_result, uint8_t** payload) * frame start sequence(2), payload length field(2), command id(1), * param(variable length), * payload end sequence(2 or 0), checksum(2), frame end sequence(2) */ - frame_len = 2 + 2 + 1 + param_len + ((model->has_payload_end_seq) ? 2 : 0) + 2 + 2; + int frame_len = 2 + 2 + 1 + param_len + ((model->has_payload_end_seq) ? 2 : 0) + 2 + 2; if (frame_len > FRAME_MAXLEN) { fatal("frame too large (frame_len=%d, FRAME_MAXLEN=%d)\n", @@ -488,13 +479,13 @@ dg100_recv_frame(struct dg100_command** cmdinfo_result, uint8_t** payload) } dg100_debug("", 0, frame_len - 7, &buf[7]); - frame_start_seq = be_read16(buf + 0); + uint16_t frame_start_seq = be_read16(buf + 0); payload_len_field = be_read16(buf + 2); if (model->has_payload_end_seq) { payload_end_seq = be_read16(buf + frame_len - 6); } - payload_checksum = be_read16(buf + frame_len - 4); - frame_end_seq = be_read16(buf + frame_len - 2); + uint16_t payload_checksum = be_read16(buf + frame_len - 4); + uint16_t frame_end_seq = be_read16(buf + frame_len - 2); (void) payload_end_seq; (void) frame_end_seq; @@ -502,7 +493,7 @@ dg100_recv_frame(struct dg100_command** cmdinfo_result, uint8_t** payload) frame_start_seq, payload_len_field, cmdinfo->text); /* calculate checksum */ - sum = dg100_checksum(buf + 4, frame_len - 8); + uint16_t sum = dg100_checksum(buf + 4, frame_len - 8); if (sum != payload_checksum) { fatal("checksum mismatch: data sum is 0x%04x, checksum received is 0x%04x\n", sum, payload_checksum); @@ -523,12 +514,10 @@ dg100_recv_frame(struct dg100_command** cmdinfo_result, uint8_t** payload) static int dg100_recv(uint8_t expected_id, void* buf, unsigned int len) { - int n; struct dg100_command* cmdinfo; uint8_t* data; - unsigned int copysize, trailing_bytes; - n = dg100_recv_frame(&cmdinfo, &data); + int n = dg100_recv_frame(&cmdinfo, &data); /* check whether the received frame matches the expected answer type */ if (cmdinfo->id != expected_id) { @@ -536,8 +525,8 @@ dg100_recv(uint8_t expected_id, void* buf, unsigned int len) return -1; } - trailing_bytes = (model->has_trailing_bytes) ? (cmdinfo->trailing_bytes) : 0; - copysize = n - trailing_bytes; + unsigned int trailing_bytes = (model->has_trailing_bytes) ? (cmdinfo->trailing_bytes) : 0; + unsigned int copysize = n - trailing_bytes; /* check for buffer overflow */ if (len < copysize) { @@ -554,9 +543,7 @@ dg100_recv(uint8_t expected_id, void* buf, unsigned int len) static int dg100_request(uint8_t cmd, const void* sendbuf, void* recvbuf, size_t count) { - struct dg100_command* cmdinfo; - - cmdinfo = dg100_findcmd(cmd); + struct dg100_command* cmdinfo = dg100_findcmd(cmd); assert(cmdinfo != nullptr); dg100_send(cmd, sendbuf, cmdinfo->sendsize); diff --git a/dmtlog.cc b/dmtlog.cc index b39f0a4b3..8428de4b2 100644 --- a/dmtlog.cc +++ b/dmtlog.cc @@ -333,15 +333,12 @@ tlog3b_xgcb_wpten(xg_string, const QXmlStreamAttributes*) static char* read_str(gbfile* f) { - int i; - char* res; - - i = gbfgetc(f); + int i = gbfgetc(f); if (i == 0xff) { i = gbfgetint16(f); } - res = (char*) xmalloc(i + 1); + char* res = (char*) xmalloc(i + 1); res[i] = '\0'; if (i) { gbfread(res, 1, i, f); @@ -384,13 +381,10 @@ write_str(const QString& str, gbfile* f) static int read_datum(gbfile* f) { - int res; - char* d, *g; - - d = read_str(f); - g = read_str(f); + char* d = read_str(f); + char* g = read_str(f); - res = GPS_Lookup_Datum_Index(d); + int res = GPS_Lookup_Datum_Index(d); if (*g && (strcmp(d, g) != 0)) { fatal(MYNAME ": Unsupported combination of datum '%s' and grid '%s'!\n", @@ -407,14 +401,9 @@ static void read_CTrackFile(const int version) { char buf[128]; - int32_t ver; - int32_t tcount, wcount; - int16_t u1; - int32_t ux; - route_head* track; int i; - u1 = gbfgetint16(fin); + int16_t u1 = gbfgetint16(fin); gbfread(buf, 1, 10, fin); if ((u1 != 0x0a) || (strncmp("CTrackFile", buf, 10) != 0)) { @@ -425,17 +414,17 @@ read_CTrackFile(const int version) gbfseek(fin, 36, SEEK_CUR); /* skip unknown 36 bytes */ } - ver = gbfgetint32(fin); + int32_t ver = gbfgetint32(fin); if (ver != version) { fatal(MYNAME ": Unknown or invalid track file (%d).\n", ver); } - ux = gbfgetint32(fin); // Unknown 2 + int32_t ux = gbfgetint32(fin); // Unknown 2 ux = gbfgetint32(fin); // Unknown 3 ux = gbfgetint32(fin); // Unknown 4 (void) ux; // Silence warning. - track = route_head_alloc(); + route_head* track = route_head_alloc(); track_add_head(track); /* S1 .. S9: comments, hints, jokes, aso */ @@ -444,29 +433,25 @@ read_CTrackFile(const int version) xfree(s); } - tcount = gbfgetint32(fin); + int32_t tcount = gbfgetint32(fin); int datum = 118; if (tcount > 0) { datum = read_datum(fin); if (version == 8) { - int len; - gbfread(buf, 1, 4, fin); - len = gbfgetint16(fin); + int len = gbfgetint16(fin); gbfseek(fin, len, SEEK_CUR); } } while (tcount > 0) { - Waypoint* wpt; - tcount--; if (version == 8) { datum = read_datum(fin); } - wpt = new Waypoint; + Waypoint* wpt = new Waypoint; wpt->latitude = gbfgetdbl(fin); wpt->longitude = gbfgetdbl(fin); @@ -505,8 +490,6 @@ read_CTrackFile(const int version) } while (! gbfeof(fin)) { - Waypoint* wpt; - i = gbfgetc(fin); if (i == 0) { break; @@ -515,7 +498,7 @@ read_CTrackFile(const int version) gbfungetc(i, fin); datum = read_datum(fin); - wpt = new Waypoint; + Waypoint* wpt = new Waypoint; wpt->latitude = gbfgetdbl(fin); wpt->longitude = gbfgetdbl(fin); @@ -532,7 +515,7 @@ read_CTrackFile(const int version) return; } - wcount = gbfgetint32(fin); + int32_t wcount = gbfgetint32(fin); if (wcount == 0) { return; } @@ -540,12 +523,9 @@ read_CTrackFile(const int version) datum = read_datum(fin); while (wcount > 0) { - Waypoint* wpt; - int32_t namect; - wcount--; - wpt = new Waypoint; + Waypoint* wpt = new Waypoint; wpt->latitude = gbfgetdbl(fin); wpt->longitude = gbfgetdbl(fin); @@ -553,14 +533,12 @@ read_CTrackFile(const int version) convert_datum(wpt, datum); - namect = gbfgetint32(fin); + int32_t namect = gbfgetint32(fin); // variants of shortname for (int32_t i = 0; i < namect; i++) { - char* name; - - name = read_str(fin); + char* name = read_str(fin); if (name && *name) { switch (i) { case 0: @@ -588,7 +566,6 @@ inflate_buff(const char* buff, const size_t size, char** out_buff) char out[DEFLATE_BUFF_SIZE]; char* cout = nullptr; uint32_t bytes = 0; - uint32_t have; strm.zalloc = Z_NULL; strm.zfree = Z_NULL; @@ -617,7 +594,7 @@ inflate_buff(const char* buff, const size_t size, char** out_buff) (void)inflateEnd(&strm); return res; } - have = DEFLATE_BUFF_SIZE - strm.avail_out; + uint32_t have = DEFLATE_BUFF_SIZE - strm.avail_out; if (have > 0) { cout = (char*) xrealloc(cout, bytes + have); memcpy(cout+bytes, out, have); @@ -731,12 +708,11 @@ dmtlog_wr_deinit() static void write_header(const route_head* trk) { - int count; const char ZERO = '\0'; header_written = 1; - count = 0; + int count = 0; if (trk != nullptr) { queue* curr, *prev; QUEUE_FOR_EACH(&trk->waypoint_list, curr, prev) count++; @@ -795,13 +771,11 @@ track_wpt_cb(const Waypoint* wpt) static void wpt_cb(const Waypoint* wpt) { - int names; - gbfputdbl(wpt->latitude, fout); gbfputdbl(wpt->longitude, fout); gbfputdbl(wpt->altitude != unknown_alt ? wpt->altitude : 0, fout); - names = 1; + int names = 1; if (!wpt->description.isEmpty()) { names = 2; } diff --git a/duplicate.cc b/duplicate.cc index f47c34094..6db106098 100644 --- a/duplicate.cc +++ b/duplicate.cc @@ -28,7 +28,7 @@ DuplicateFilter::btree_node* DuplicateFilter::addnode(btree_node* tree, btree_node* newnode, btree_node** oldnode) { - btree_node* tmp, * last = nullptr; + btree_node* last = nullptr; if (*oldnode) { *oldnode = nullptr; @@ -38,7 +38,7 @@ DuplicateFilter::btree_node* DuplicateFilter::addnode(btree_node* tree, btree_no return (newnode); } - tmp = tree; + btree_node* tmp = tree; while (tmp) { last = tmp; @@ -144,14 +144,13 @@ void DuplicateFilter::process(void) } dupe; Waypoint* delwpt = nullptr; - int i, ct = waypt_count(); - wpt_ptr* htable, *bh; + int ct = waypt_count(); queue* elem, *tmp; - htable = (wpt_ptr*) xmalloc(ct * sizeof(*htable)); - bh = htable; + wpt_ptr* htable = (wpt_ptr*) xmalloc(ct * sizeof(*htable)); + wpt_ptr* bh = htable; - i = 0; + int i = 0; #if NEWQ foreach (Waypoint* waypointp, waypt_list) { bh->wpt = waypointp; diff --git a/easygps.cc b/easygps.cc index 616d6c602..e6d9a6c99 100644 --- a/easygps.cc +++ b/easygps.cc @@ -39,13 +39,12 @@ arglist_t easygps_args[] = { static void rd_init(const QString& fname) { - int sz; char ibuf[100] = {'0'} ; const char* ezsig = "TerraByte Location File"; file_in = gbfopen_le(fname, "rb", MYNAME); - sz = gbfread(ibuf, 1, 52, file_in); + int sz = gbfread(ibuf, 1, 52, file_in); if ((sz < 52) || strncmp(ibuf, ezsig, strlen(ezsig)) || @@ -80,13 +79,10 @@ data_read() char p; char ibuf[10]; do { - unsigned char tag; - Waypoint* wpt_tmp; - - wpt_tmp = new Waypoint; + Waypoint* wpt_tmp = new Waypoint; UrlLink link; - for (tag = gbfgetc(file_in); tag != 0xff; tag = gbfgetc(file_in)) { + for (unsigned char tag = gbfgetc(file_in); tag != 0xff; tag = gbfgetc(file_in)) { switch (tag) { case 1: wpt_tmp->shortname = gbfgetpstr(file_in); diff --git a/energympro.cc b/energympro.cc index 33d129aec..0512cc24b 100644 --- a/energympro.cc +++ b/energympro.cc @@ -156,8 +156,7 @@ read_point(route_head* gpsbabel_route,gpsbabel::DateTime& gpsDateTime) qint64 mSecsSinceEpoc = gpsbabeltime.toMSecsSinceEpoch(); gpsbabeltime.setMSecsSinceEpoch(mSecsSinceEpoc-mSecsSinceEpoc%1000); - Waypoint* waypt; - waypt = new Waypoint; + Waypoint* waypt = new Waypoint; waypt->latitude = (point.Latitude / 1000000.0); waypt->longitude = (point.Longitude / 1000000.0); waypt->altitude = point.Altitude; @@ -215,8 +214,7 @@ rd_init(const QString& fname) /* copy file to memory stream (needed for seek-ops and piped commands) */ file_in = gbfopen(nullptr, "wb", MYNAME); - gbsize_t size; - size = gbfcopyfrom(file_in, fileorg_in, 0x7FFFFFFF); + gbsize_t size = gbfcopyfrom(file_in, fileorg_in, 0x7FFFFFFF); if(global_opts.debug_level > 1) { printf (MYNAME " filesize=%d\n",size); } diff --git a/exif.cc b/exif.cc index 5081b0b79..a31220b41 100644 --- a/exif.cc +++ b/exif.cc @@ -216,9 +216,7 @@ exif_type_size(const uint16_t type) static QString exif_time_str(const time_t time) { - struct tm tm; - - tm = *localtime(&time); + struct tm tm = *localtime(&time); tm.tm_year += 1900; tm.tm_mon += 1; @@ -238,11 +236,10 @@ exif_read_str(exif_tag_t* tag) static double exif_read_double(const exif_tag_t* tag, const int index) { - unsigned int num, den; int32_t* data = (int32_t*)tag->data; - num = data[index * 2]; - den = data[(index * 2) + 1]; + unsigned int num = data[index * 2]; + unsigned int den = data[(index * 2) + 1]; if (den == 0) { den = 1; } @@ -253,20 +250,18 @@ exif_read_double(const exif_tag_t* tag, const int index) static double exif_read_coord(const exif_tag_t* tag) { - double res, min, sec; - - res = exif_read_double(tag, 0); + double res = exif_read_double(tag, 0); if (tag->count == 1) { return res; } - min = exif_read_double(tag, 1); + double min = exif_read_double(tag, 1); res += (min / 60); if (tag->count == 2) { return res; } - sec = exif_read_double(tag, 2); + double sec = exif_read_double(tag, 2); res += (sec / 3600); return res; @@ -275,11 +270,9 @@ exif_read_coord(const exif_tag_t* tag) static time_t exif_read_timestamp(const exif_tag_t* tag) { - double hour, min, sec; - - hour = exif_read_double(tag, 0); - min = exif_read_double(tag, 1); - sec = exif_read_double(tag, 2); + double hour = exif_read_double(tag, 0); + double min = exif_read_double(tag, 1); + double sec = exif_read_double(tag, 2); return ((int)hour * SECONDS_PER_HOUR) + ((int)min * 60) + (int)sec; } @@ -288,10 +281,9 @@ static time_t exif_read_datestamp(const exif_tag_t* tag) { struct tm tm; - char* str; memset(&tm, 0, sizeof(tm)); - str = xstrndup((char*)tag->data, tag->size); + char* str = xstrndup((char*)tag->data, tag->size); sscanf(str, "%d:%d:%d", &tm.tm_year, &tm.tm_mon, &tm.tm_mday); xfree(str); @@ -406,10 +398,9 @@ exif_read_ifd(exif_app_t* app, const uint16_t ifd_nr, gbsize_t offs, uint32_t* exif_ifd_ofs, uint32_t* gps_ifd_ofs, uint32_t* inter_ifd_ofs) { queue* elem, *tmp; - exif_ifd_t* ifd; gbfile* fin = app->fexif; - ifd = (exif_ifd_t*) xcalloc(sizeof(*ifd), 1); + exif_ifd_t* ifd = (exif_ifd_t*) xcalloc(sizeof(*ifd), 1); QUEUE_INIT(&ifd->tags); ENQUEUE_TAIL(&app->ifds, &ifd->Q); ifd->nr = ifd_nr; @@ -449,9 +440,7 @@ exif_read_ifd(exif_app_t* app, const uint16_t ifd_nr, gbsize_t offs, } for (uint16_t i = 0; i < ifd->count; i++) { - exif_tag_t* tag; - - tag = (exif_tag_t*) xcalloc(sizeof(*tag), 1); + exif_tag_t* tag = (exif_tag_t*) xcalloc(sizeof(*tag), 1); #ifdef EXIF_DBG offs = gbftell(fin); tag->offs = offs; @@ -493,12 +482,10 @@ exif_read_ifd(exif_app_t* app, const uint16_t ifd_nr, gbsize_t offs, QUEUE_FOR_EACH(&ifd->tags, elem, tmp) { exif_tag_t* tag = (exif_tag_t*)elem; if ((tag->size > 4) && (tag->value)) { - char* ptr; - tag->data = xmalloc(tag->size); tag->data_is_dynamic = 1; - ptr = (char*) tag->data; + char* ptr = (char*) tag->data; gbfseek(fin, tag->value, SEEK_SET); if (BYTE_TYPE(tag->type)) { @@ -591,15 +578,13 @@ exif_read_app(exif_app_t* app) static void exif_examine_app(exif_app_t* app) { - uint16_t endianess; - uint32_t ident; gbfile* ftmp = exif_app->fcache; gbfrewind(ftmp); - ident = gbfgetuint32(ftmp); + uint32_t ident = gbfgetuint32(ftmp); is_fatal(ident != 0x66697845, MYNAME ": Invalid EXIF header magic."); is_fatal(gbfgetint16(ftmp) != 0, MYNAME ": Error in EXIF header."); - endianess = gbfgetint16(ftmp); + uint16_t endianess = gbfgetint16(ftmp); #ifdef EXIF_DBG printf(MYNAME ": endianess = 0x%04X\n", endianess); @@ -656,9 +641,7 @@ exif_get_exif_time(exif_app_t* app) { QDateTime res; - exif_tag_t* tag; - - tag = exif_find_tag(app, EXIF_IFD, 0x9003); /* DateTimeOriginal from EXIF */ + exif_tag_t* tag = exif_find_tag(app, EXIF_IFD, 0x9003); /* DateTimeOriginal from EXIF */ if (! tag) { tag = exif_find_tag(app, IFD0, 0x0132); /* DateTime from IFD0 */ } @@ -667,9 +650,7 @@ exif_get_exif_time(exif_app_t* app) } if (tag) { - char* str; - - str = exif_read_str(tag); + char* str = exif_read_str(tag); res = QDateTime::fromString(str, "yyyy:MM:dd hh:mm:ss"); xfree(str); } @@ -679,9 +660,7 @@ exif_get_exif_time(exif_app_t* app) static Waypoint* exif_waypt_from_exif_app(exif_app_t* app) { - Waypoint* wpt; queue* elem, *tmp; - exif_ifd_t* ifd; exif_tag_t* tag; char lat_ref = '\0'; char lon_ref = '\0'; @@ -694,12 +673,12 @@ exif_waypt_from_exif_app(exif_app_t* app) time_t timestamp = UNKNOWN_TIMESTAMP; time_t datestamp = UNKNOWN_TIMESTAMP; - ifd = exif_find_ifd(app, GPS_IFD); + exif_ifd_t* ifd = exif_find_ifd(app, GPS_IFD); if (ifd == nullptr) { return nullptr; } - wpt = new Waypoint; + Waypoint* wpt = new Waypoint; wpt->latitude = unknown_alt; wpt->longitude = unknown_alt; @@ -878,10 +857,10 @@ exif_waypt_from_exif_app(exif_app_t* app) } if (opt_filename) { - char* c, *cx; + char* c; char* str = xstrdup(fin->name); - cx = str; + char* cx = str; if ((c = strrchr(cx, ':'))) { cx = c + 1; } @@ -907,9 +886,6 @@ exif_dec2frac(double val, int32_t* num, int32_t* den) char sval[16], snum[16]; char dot = 0; int den1 = 1; - int num1, num2, den2, rem; - char* cx; - double vx; if (val < 0.000000001) { val = 0.0; @@ -917,8 +893,8 @@ exif_dec2frac(double val, int32_t* num, int32_t* den) fatal(MYNAME ": Value (%f) to big for a rational representation!\n", val); } - num1 = 0; - vx = fabs(val); + int num1 = 0; + double vx = fabs(val); while (vx > 1) { num1++; vx = vx / 10; @@ -927,7 +903,7 @@ exif_dec2frac(double val, int32_t* num, int32_t* den) snprintf(sval, sizeof(sval), "%*.*f", 9, 9 - num1, fabs(val)); snum[0] = '\0'; - cx = sval; + char* cx = sval; while (*cx) { if (dot) { den1 *= 10; @@ -946,9 +922,9 @@ exif_dec2frac(double val, int32_t* num, int32_t* den) *den = den1; } - num2 = num1; - den2 = den1; - rem = 1; + int num2 = num1; + int den2 = den1; + int rem = 1; /* Euclid's Algorithm to find the gcd */ while (num2 % den2) { @@ -968,10 +944,9 @@ static exif_tag_t* exif_put_value(const int ifd_nr, const uint16_t tag_id, const uint16_t type, const uint32_t count, const int index, const void* data) { exif_tag_t* tag = nullptr; - exif_ifd_t* ifd; - uint16_t item_size, size; + uint16_t size; - ifd = exif_find_ifd(exif_app, ifd_nr); + exif_ifd_t* ifd = exif_find_ifd(exif_app, ifd_nr); if (ifd == nullptr) { ifd = (exif_ifd_t*) xcalloc(sizeof(*ifd), 1); ifd->nr = ifd_nr; @@ -981,7 +956,7 @@ exif_put_value(const int ifd_nr, const uint16_t tag_id, const uint16_t type, con tag = exif_find_tag(exif_app, ifd_nr, tag_id); } - item_size = exif_type_size(type); + uint16_t item_size = exif_type_size(type); if ((data == nullptr) || (count < 1) || (index < 0)) { size = 0; @@ -1071,12 +1046,9 @@ exif_put_str(const int ifd_nr, const int tag_id, const char* val) static void exif_put_coord(const int ifd_nr, const int tag_id, const double val) { - double vmin, vsec; - int vint; - - vint = abs((int) val); - vmin = 60.0 * (fabs(val) - vint); - vsec = 60.0 * (vmin - floor(vmin)); + int vint = abs((int) val); + double vmin = 60.0 * (fabs(val) - vint); + double vsec = 60.0 * (vmin - floor(vmin)); vmin = floor(vmin); exif_put_double(ifd_nr, tag_id, 0, (double)vint); @@ -1165,11 +1137,10 @@ exif_write_value(exif_tag_t* tag, gbfile* fout) static void exif_write_ifd(const exif_ifd_t* ifd, const char next, gbfile* fout) { - gbsize_t offs; queue* elem, *tmp; gbfputuint16(ifd->count, fout); - offs = gbftell(fout) + (ifd->count * 12) + 4; + gbsize_t offs = gbftell(fout) + (ifd->count * 12) + 4; QUEUE_FOR_EACH(&ifd->tags, elem, tmp) { exif_tag_t* tag = (exif_tag_t*)elem; @@ -1253,7 +1224,6 @@ exif_write_apps() if (app == exif_app) { queue* e1, *t1; uint16_t len = 8; - gbfile* ftmp; exif_tag_t* tag; exif_put_long(IFD0, IFD0_TAG_GPS_IFD_OFFS, 0, 0); @@ -1286,7 +1256,7 @@ exif_write_apps() sortqueue(&ifd->tags, exif_sort_tags_cb); } - ftmp = gbfopen_be(nullptr, "wb", MYNAME); + gbfile* ftmp = gbfopen_be(nullptr, "wb", MYNAME); ftmp->big_endian = app->fcache->big_endian; gbfwrite((ftmp->big_endian) ? "MM" : "II", 2, 1, ftmp); @@ -1354,17 +1324,14 @@ exif_rd_deinit() static void exif_read() { - uint16_t soi; - Waypoint* wpt; - - soi = gbfgetuint16(fin); + uint16_t soi = gbfgetuint16(fin); is_fatal(soi != 0xFFD8, MYNAME ": Unknown image file."); /* only jpeg for now */ exif_app = exif_load_apps(); is_fatal(exif_app == nullptr, MYNAME ": No EXIF header in source file \"%s\".", fin->name); exif_examine_app(exif_app); - wpt = exif_waypt_from_exif_app(exif_app); + Waypoint* wpt = exif_waypt_from_exif_app(exif_app); if (wpt) { waypt_add(wpt); } @@ -1373,8 +1340,6 @@ exif_read() static void exif_wr_init(const QString& fname) { - uint16_t soi; - exif_success = 0; exif_fout_name = fname; @@ -1383,7 +1348,7 @@ exif_wr_init(const QString& fname) fin = gbfopen_be(fname, "rb", MYNAME); is_fatal(fin->is_pipe, MYNAME ": Sorry, this format cannot be used with pipes!"); - soi = gbfgetuint16(fin); + uint16_t soi = gbfgetuint16(fin); is_fatal(soi != 0xFFD8, MYNAME ": Unknown image file."); exif_app = exif_load_apps(); is_fatal(exif_app == nullptr, MYNAME ": No EXIF header found in source file \"%s\".", fin->name); @@ -1423,8 +1388,6 @@ exif_wr_deinit() static void exif_write() { - time_t frame; - exif_wpt_ref = nullptr; if (opt_name) { @@ -1445,7 +1408,7 @@ exif_write() route_disp_all(nullptr, nullptr, exif_find_wpt_by_time); waypt_disp_all(exif_find_wpt_by_time); - frame = atoi(opt_frame); + time_t frame = atoi(opt_frame); if (exif_wpt_ref == nullptr) { warning(MYNAME ": No point with a valid timestamp found.\n"); @@ -1487,11 +1450,10 @@ exif_write() } if (wpt->creation_time.isValid()) { - struct tm tm; char buf[32]; const time_t tt = wpt->GetCreationTime().toTime_t(); - tm = *gmtime(&tt); + struct tm tm = *gmtime(&tt); tm.tm_year += 1900; tm.tm_mon += 1; diff --git a/explorist_ini.cc b/explorist_ini.cc index 3db42ae5d..3b668e7dc 100644 --- a/explorist_ini.cc +++ b/explorist_ini.cc @@ -17,7 +17,6 @@ static mag_info* explorist_ini_try(const char* path) { char* inipath; - char* s; xasprintf(&inipath, "%s/%s", path, "APP/Atlas.ini"); inifile = inifile_init(QString::fromUtf8(inipath), myname); @@ -31,7 +30,7 @@ explorist_ini_try(const char* path) info->track_path = nullptr; info->waypoint_path = nullptr; - s = xstrdup(inifile_readstr(inifile, "UGDS", "WpFolder")); + char* s = xstrdup(inifile_readstr(inifile, "UGDS", "WpFolder")); if (s) { s = gstrsub(s, "\\", "/"); xasprintf(&info->waypoint_path, "%s/%s", path, s); diff --git a/f90g_track.cc b/f90g_track.cc index 3ec02e1b8..f5c5588b6 100644 --- a/f90g_track.cc +++ b/f90g_track.cc @@ -88,10 +88,8 @@ static const float SPEED_CONVERSION = (10.0f)/(36.0f); // convert KPH to meters static void f90g_track_read() { - Waypoint* readWaypoint; char northSouth, eastWest, velocityMark, ttRec[TTRECORDSIZE], tempBuf[20]; int year, mon, mday, hour, min, sec, latitudeDeg, latitudeMin, longitudeDeg, longitudeMin, velocity; - QDateTime dt; is_fatal((track == nullptr), MYNAME "Track setup error"); for (;;) { @@ -121,8 +119,8 @@ f90g_track_read() && velocityMark == 'M') { // create the Waypoint and fill it in - readWaypoint = new Waypoint; - dt = QDateTime(QDate(year, mon, mday), QTime(hour, min, sec), Qt::UTC); + Waypoint* readWaypoint = new Waypoint; + QDateTime dt = QDateTime(QDate(year, mon, mday), QTime(hour, min, sec), Qt::UTC); readWaypoint->SetCreationTime(dt); readWaypoint->latitude = (double(latitudeDeg) + double(latitudeMin)/MIN_PER_DEGREE) diff --git a/filter_vecs.cc b/filter_vecs.cc index cc66864fc..1bf3342b3 100644 --- a/filter_vecs.cc +++ b/filter_vecs.cc @@ -191,7 +191,6 @@ find_filter_vec(const char* const vecname, const char** opts) while (vec->vec) { arglist_t* ap; - const char* res; if (svecname.compare(vec->name, Qt::CaseInsensitive)) { vec++; @@ -202,9 +201,7 @@ find_filter_vec(const char* const vecname, const char** opts) struct arglist* args = vec->vec->get_args(); if (args) { for (ap = args; ap->argstring; ap++) { - const char* temp; - - temp = inifile_readstr(global_opts.inifile, vec->name, ap->argstring); + const char* temp = inifile_readstr(global_opts.inifile, vec->name, ap->argstring); if (temp == nullptr) { temp = inifile_readstr(global_opts.inifile, "Common filter settings", ap->argstring); } @@ -216,15 +213,13 @@ find_filter_vec(const char* const vecname, const char** opts) } /* step 2: override settings with command-line values */ - res = strchr(vecname, ','); + const char* res = strchr(vecname, ','); if (res) { *opts = res+1; if (args) { for (ap = args; ap->argstring; ap++) { - char* opt; - - opt = get_option(*opts, ap->argstring); + char* opt = get_option(*opts, ap->argstring); if (opt) { found = 1; assign_option(vec->name, ap, opt); @@ -254,11 +249,10 @@ find_filter_vec(const char* const vecname, const char** opts) void free_filter_vec(Filter* filter) { - arglist_t* ap; struct arglist* args = filter->get_args(); if (args) { - for (ap = args; ap->argstring; ap++) { + for (arglist_t* ap = args; ap->argstring; ap++) { if (ap->argvalptr) { xfree(ap->argvalptr); ap->argvalptr = *ap->argval = nullptr; @@ -272,10 +266,9 @@ init_filter_vecs() { fl_vecs_t* vec = filter_vec_list; while (vec->vec) { - arglist_t* ap; struct arglist* args = vec->vec->get_args(); if (args) { - for (ap = args; ap->argstring; ap++) { + for (arglist_t* ap = args; ap->argstring; ap++) { ap->argvalptr = nullptr; } } @@ -300,14 +293,11 @@ exit_filter_vecs() void disp_filter_vecs() { - fl_vecs_t* vec; - arglist_t* ap; - - for (vec = filter_vec_list; vec->vec; vec++) { + for (fl_vecs_t* vec = filter_vec_list; vec->vec; vec++) { printf(" %-20.20s %-50.50s\n", vec->name, vec->desc); struct arglist* args = vec->vec->get_args(); - for (ap = args; ap && ap->argstring; ap++) { + for (arglist_t* ap = args; ap && ap->argstring; ap++) { if (!(ap->argtype & ARGTYPE_HIDDEN)) printf(" %-18.18s %-.50s %s\n", ap->argstring, ap->helpstring, @@ -319,17 +309,14 @@ disp_filter_vecs() void disp_filter_vec(const char* vecname) { - fl_vecs_t* vec; - arglist_t* ap; - - for (vec = filter_vec_list; vec->vec; vec++) { + for (fl_vecs_t* vec = filter_vec_list; vec->vec; vec++) { if (case_ignore_strcmp(vec->name, vecname)) { continue; } printf(" %-20.20s %-50.50s\n", vec->name, vec->desc); struct arglist* args = vec->vec->get_args(); - for (ap = args; ap && ap->argstring; ap++) { + for (arglist_t* ap = args; ap && ap->argstring; ap++) { if (!(ap->argtype & ARGTYPE_HIDDEN)) printf(" %-18.18s %-.50s %s\n", ap->argstring, ap->helpstring, @@ -359,12 +346,10 @@ void disp_help_url(const fl_vecs_t* vec, arglist_t* arg) static void disp_v1(const fl_vecs_t* vec) { - arglist_t* ap; - disp_help_url(vec, nullptr); printf("\n"); struct arglist* args = vec->vec->get_args(); - for (ap = args; ap && ap->argstring; ap++) { + for (arglist_t* ap = args; ap && ap->argstring; ap++) { if (!(ap->argtype & ARGTYPE_HIDDEN)) { printf("option\t%s\t%s\t%s\t%s\t%s\t%s\t%s", vec->name, diff --git a/g7towin.cc b/g7towin.cc index ecf5620ac..39e112081 100644 --- a/g7towin.cc +++ b/g7towin.cc @@ -270,14 +270,11 @@ parse_line(char* buff, int index, const char* delimiter, Waypoint* wpt) static Waypoint* parse_waypt(char* buff) { - char* cin, *cerr; - int i; + char* cin; struct tm tm; - Waypoint* wpt; - garmin_fs_p gmsd; - wpt = new Waypoint; - gmsd = garmin_fs_alloc(-1); + Waypoint* wpt = new Waypoint; + garmin_fs_p gmsd = garmin_fs_alloc(-1); fs_chain_add(&wpt->fs, (format_specific_data*) gmsd); if (gardown) { @@ -315,14 +312,14 @@ parse_waypt(char* buff) } memset(&tm, 0, sizeof(tm)); - cerr = strptime(buff, "%a %b %d %H:%M:%S %Y", &tm); + char* cerr = strptime(buff, "%a %b %d %H:%M:%S %Y", &tm); if (cerr == nullptr) { fatal(MYNAME ": Unable to convert date (%s)!\n", buff); } wpt->SetCreationTime(mkgmtime(&tm)); /* go over time stamp */ - i = 5; + int i = 5; while (buff && i) { i--; buff = strchr(buff, ' '); @@ -347,11 +344,8 @@ parse_waypt(char* buff) static Waypoint* parse_trkpt(char* buff) { - garmin_fs_p gmsd; - Waypoint* wpt; - - wpt = new Waypoint; - gmsd = garmin_fs_alloc(-1); + Waypoint* wpt = new Waypoint; + garmin_fs_p gmsd = garmin_fs_alloc(-1); fs_chain_add(&wpt->fs, (format_specific_data*) gmsd); parse_line(buff, TRKPT__OFS, ";", wpt); @@ -416,8 +410,6 @@ data_read(void) route_head* head = nullptr; while ((buff = gbfgetstr(fin))) { - char* cdata; - if ((line++ == 0) && fin->unicode) { cet_convert_init(CET_CHARSET_UTF8, 1); } @@ -427,7 +419,7 @@ data_read(void) continue; } - cdata = cin+1; + char* cdata = cin+1; while (! isspace(*cdata)) { cdata++; } @@ -535,8 +527,7 @@ data_read(void) cdata++; } if (*cdata) { - char* s; - s = strrchr(cdata, ','); + char* s = strrchr(cdata, ','); if (s) { *s = '\0'; s = strrchr(cdata, ','); diff --git a/garmin.cc b/garmin.cc index affdf60d6..9b08c7e05 100644 --- a/garmin.cc +++ b/garmin.cc @@ -112,7 +112,6 @@ static int d103_icon_number_from_symbol(const QString& s); static void rw_init(const QString& fname) { - int receiver_short_length; int receiver_must_upper = 1; const char* receiver_charset = nullptr; @@ -181,7 +180,7 @@ rw_init(const QString& fname) * Fortunately, getting this "wrong" only results in ugly names * when we're using the synthesize_shortname path. */ - receiver_short_length = 10; + int receiver_short_length = 10; switch (gps_waypt_type) { /* waypoint type as defined by jeeps */ case 0: @@ -473,7 +472,6 @@ static void track_read() { - int32 ntracks; GPS_PTrack* array; route_head* trk_head = nullptr; int trk_num = 0; @@ -487,15 +485,13 @@ track_read() } - ntracks = GPS_Command_Get_Track(portname, &array, waypt_read_cb); + int32 ntracks = GPS_Command_Get_Track(portname, &array, waypt_read_cb); if (ntracks <= 0) { return; } for (int i = 0; i < ntracks; i++) { - Waypoint* wpt; - /* * This is probably always in slot zero, but the Garmin * serial spec says these can appear anywhere. Toss them @@ -526,7 +522,7 @@ track_read() if (array[i]->no_latlon || array[i]->ishdr) { continue; } - wpt = new Waypoint; + Waypoint* wpt = new Waypoint; wpt->longitude = array[i]->lon; wpt->latitude = array[i]->lat; @@ -560,7 +556,6 @@ static void route_read() { - int32 nroutepts; GPS_PWay* array; /* TODO: Fixes warning but is it right? * RJL: No, the warning isn't right; GCC's flow analysis is broken. @@ -568,7 +563,7 @@ route_read() */ route_head* rte_head = nullptr; - nroutepts = GPS_Command_Get_Route(portname, &array); + int32 nroutepts = GPS_Command_Get_Route(portname, &array); // fprintf(stderr, "Routes %d\n", (int) nroutepts); #if 1 @@ -710,8 +705,6 @@ lap_read_as_track(void) static void pvt2wpt(GPS_PPvt_Data pvt, Waypoint* wpt) { - double wptime, wptimes; - wpt->altitude = pvt->alt; wpt->latitude = pvt->lat; wpt->longitude = pvt->lon; @@ -731,10 +724,10 @@ pvt2wpt(GPS_PPvt_Data pvt, Waypoint* wpt) * 3) The number of leap seconds that offset the current UTC and GPS * reference clocks. */ - wptime = 631065600.0 + pvt->wn_days * 86400.0 + - pvt->tow - - pvt->leap_scnds; - wptimes = floor(wptime); + double wptime = 631065600.0 + pvt->wn_days * 86400.0 + + pvt->tow + - pvt->leap_scnds; + double wptimes = floor(wptime); wpt->SetCreationTime(wptimes, 1000000.0 * (wptime - wptimes)); /* @@ -843,8 +836,7 @@ data_read() static GPS_PWay sane_GPS_Way_New() { - GPS_PWay way; - way = GPS_Way_New(); + GPS_PWay way = GPS_Way_New(); if (!way) { fatal(MYNAME ":not enough memory\n"); } @@ -942,7 +934,6 @@ waypoint_prepare() QUEUE_FOR_EACH(&waypt_head, elem, tmp) { Waypoint* wpt = (Waypoint*) elem; #endif - char* ident; char obuf[256]; QString src; @@ -957,9 +948,9 @@ waypoint_prepare() * mkshort will do collision detection and namespace * cleaning */ - ident = mkshort(mkshort_handle, - global_opts.synthesize_shortnames ? CSTRc(src) : - CSTRc(wpt->shortname)); + char* ident = mkshort(mkshort_handle, + global_opts.synthesize_shortnames ? CSTRc(src) : + CSTRc(wpt->shortname)); /* Should not be a strcpy as 'ident' isn't really a C string, * but rather a garmin "fixed length" buffer that's padded * to the end with spaces. So this is NOT (strlen+1). @@ -1038,10 +1029,9 @@ waypoint_prepare() static void waypoint_write() { - int n; int32 ret; - n = waypoint_prepare(); + int n = waypoint_prepare(); if ((ret = GPS_Command_Send_Waypoint(portname, tx_waylist, n, waypt_write_cb)) < 0) { fatal(MYNAME ":communication error sending wayoints..\n"); @@ -1099,12 +1089,7 @@ route_waypt_pr(const Waypoint* wpt) rte->alt = 0; } - // Garmin protocol spec says no spaces, no lowercase, etc. in a route. - // enforce that here, since jeeps doesn't. - // - // This was strncpy(rte->ident, wpt->shortname, sizeof(rte->ident)); - char* d; - d = rte->ident; + char* d = rte->ident; for (auto idx : wpt->shortname) { int c = idx.toLatin1(); if (receiver_must_upper && isalpha(c)) { @@ -1196,9 +1181,7 @@ track_prepare() static void track_write() { - int n; - - n = track_prepare(); + int n = track_prepare(); GPS_Command_Send_Track(portname, tx_tracklist, n, (eraset)? 1 : 0); for (int i = 0; i < n; i++) { @@ -1210,10 +1193,10 @@ track_write() static void course_write() { - int i, n_trk, n_wpt; + int i; - n_wpt = waypoint_prepare(); - n_trk = track_prepare(); + int n_wpt = waypoint_prepare(); + int n_trk = track_prepare(); GPS_Command_Send_Track_As_Course(portname, tx_tracklist, n_trk, tx_waylist, n_wpt, (eraset)? 1 : 0); diff --git a/garmin_device_xml.cc b/garmin_device_xml.cc index ca2a7546f..73f91aeb2 100644 --- a/garmin_device_xml.cc +++ b/garmin_device_xml.cc @@ -142,12 +142,11 @@ gdx_read(const char* fname) const gdx_info* gdx_find_file(char** dirlist) { - const gdx_info* gdx; while (dirlist && *dirlist) { char* tbuf; xasprintf(&tbuf, "%s/%s", *dirlist, "/Garmin/GarminDevice.xml"); mountpoint = *dirlist; - gdx = gdx_read(tbuf); + const gdx_info* gdx = gdx_read(tbuf); xfree(tbuf); if (gdx) { longjmp(gdx_jmp_buf, 1); diff --git a/garmin_fit.cc b/garmin_fit.cc index 3e57e3d37..6eeb0266a 100644 --- a/garmin_fit.cc +++ b/garmin_fit.cc @@ -128,11 +128,9 @@ fit_rd_deinit() static void fit_parse_header() { - int len; - int ver; char sig[4]; - len = gbfgetc(fin); + int len = gbfgetc(fin); if (len == EOF || len < 12) { fatal(MYNAME ": Bad header\n"); } @@ -140,7 +138,7 @@ fit_parse_header() debug_print(1,"%s: header len=%d\n", MYNAME, len); } - ver = gbfgetc(fin); + int ver = gbfgetc(fin); if (ver == EOF || (ver >> 4) > 2) fatal(MYNAME ": Unsupported protocol version %d.%d\n", ver >> 4, ver & 0xf); @@ -175,8 +173,6 @@ fit_parse_header() static uint8_t fit_getuint8() { - int val; - if (fit_data.len == 0) { // fail gracefully for GARMIN Edge 800 with newest firmware, seems to write a wrong record length // for the last record. @@ -186,7 +182,7 @@ fit_getuint8() } return 0; } - val = gbfgetc(fin); + int val = gbfgetc(fin); if (val == EOF) { fatal(MYNAME ": unexpected end of file with fit_data.len=%d\n",fit_data.len); } @@ -238,7 +234,6 @@ fit_parse_definition_message(uint8_t header) { int local_id = header & 0x0f; fit_message_def* def = &fit_data.message_def[local_id]; - int i; if (def->fields) { xfree(def->fields); @@ -246,7 +241,7 @@ fit_parse_definition_message(uint8_t header) // first byte is reserved. It's usually 0 and we don't know what it is, // but we've seen some files that are 0x40. So we just read it and toss it. - i = fit_getuint8(); + int i = fit_getuint8(); // second byte is endianness def->endian = fit_getuint8(); @@ -405,9 +400,7 @@ fit_read_field(fit_field_t* f) static void fit_parse_data(fit_message_def* def, int time_offset) { - fit_field_t* f; uint32_t timestamp = fit_data.last_timestamp + time_offset; - uint32_t val; int32_t lat = 0x7fffffff; int32_t lon = 0x7fffffff; uint16_t alt = 0xffff; @@ -432,8 +425,8 @@ fit_parse_data(fit_message_def* def, int time_offset) if (global_opts.debug_level >= 7) { debug_print(7,"%s: parsing field %d\n", MYNAME, i); } - f = &def->fields[i]; - val = fit_read_field(f); + fit_field_t* f = &def->fields[i]; + uint32_t val = fit_read_field(f); if (f->id == kFieldTimestamp) { if (global_opts.debug_level >= 7) { debug_print(7,"%s: parsing fit data: timestamp=%d\n", MYNAME, val); @@ -679,9 +672,7 @@ fit_parse_compressed_message(uint8_t header) static void fit_parse_record() { - uint8_t header; - - header = fit_getuint8(); + uint8_t header = fit_getuint8(); // high bit 7 set -> compressed message (0 for normal) // second bit 6 set -> 0 for data message, 1 for definition message // bit 5 -> message type specific diff --git a/garmin_fs.cc b/garmin_fs.cc index 80d38f68f..fd7cae63b 100644 --- a/garmin_fs.cc +++ b/garmin_fs.cc @@ -183,7 +183,6 @@ void garmin_fs_xml_fprint(const Waypoint* waypt, QXmlStreamWriter* writer) { - const char* phone, *addr; garmin_fs_t* gmsd = GMSD_FIND(waypt); if (gmsd == nullptr) { @@ -191,7 +190,7 @@ garmin_fs_xml_fprint(const Waypoint* waypt, } /* Find out if there is at least one field set */ - addr = GMSD_GET(addr, ""); + const char* addr = GMSD_GET(addr, ""); if (! *addr) { addr = GMSD_GET(city, ""); } @@ -205,7 +204,7 @@ garmin_fs_xml_fprint(const Waypoint* waypt, addr = GMSD_GET(state, ""); } - phone = GMSD_GET(phone_nr, ""); + const char* phone = GMSD_GET(phone_nr, ""); if (*addr || *phone || (gmsd->flags.category && gmsd->category) || @@ -287,10 +286,9 @@ garmin_fs_xml_fprint(const Waypoint* waypt, void garmin_fs_xml_convert(const int base_tag, int tag, const QString& Qcdatastr, Waypoint* waypt) { - garmin_fs_t* gmsd; -// FIXME: eliminate C string copy/use here: + // FIXME: eliminate C string copy/use here: const char *cdatastr = xstrdup(Qcdatastr); - gmsd = GMSD_FIND(waypt); + garmin_fs_t* gmsd = GMSD_FIND(waypt); if (gmsd == nullptr) { gmsd = garmin_fs_alloc(-1); fs_chain_add(&waypt->fs, (format_specific_data*) gmsd); @@ -383,14 +381,13 @@ garmin_fs_convert_category(const char* category_name, uint16_t* category) } else if (global_opts.inifile != nullptr) { // Do we have a gpsbabel.ini that maps category names to category #'s? for (i = 0; i < 16; i++) { - char* c; char key[3]; // use assertion to silence gcc 7.3 warning // warning: ‘%d’ directive output may be truncated writing between 1 and 11 bytes into a region of size 3 [-Wformat-truncation=] assert((i>=0) && (i<16)); snprintf(key, sizeof(key), "%d", i + 1); - c = inifile_readstr(global_opts.inifile, GMSD_SECTION_CATEGORIES, key); + char* c = inifile_readstr(global_opts.inifile, GMSD_SECTION_CATEGORIES, key); if ((c != nullptr) && (case_ignore_strcmp(c, category_name) == 0)) { cat = (1 << i); break; @@ -409,14 +406,13 @@ unsigned char garmin_fs_merge_category(const char* category_name, Waypoint* waypt) { uint16_t cat; - garmin_fs_t* gmsd; // Attempt to get a textual category name to a category number. if (!garmin_fs_convert_category(category_name, &cat)) { return 0; } - gmsd = GMSD_FIND(waypt); + garmin_fs_t* gmsd = GMSD_FIND(waypt); cat = cat | (GMSD_GET(category, 0)); if (gmsd == nullptr) { diff --git a/garmin_gpi.cc b/garmin_gpi.cc index 8775da69c..9bb2c5852 100644 --- a/garmin_gpi.cc +++ b/garmin_gpi.cc @@ -247,11 +247,10 @@ static char* gpi_read_lc_string_old(char* languagecode, short* length) { char lc[3]; - short len; gbfread(lc, 1, 2, fin); lc[2] = '\0'; - len = gbfgetint16(fin); + short len = gbfgetint16(fin); if ((lc[0] < 'A') || (lc[0] > 'Z') || (lc[1] < 'A') || (lc[1] > 'Z')) { fatal(MYNAME ": Invalid language code %s!\n", lc); @@ -272,14 +271,11 @@ gpi_read_lc_string_old(char* languagecode, short* length) static char* gpi_read_string_old(const char* field) { - int l0; char* res = nullptr; - l0 = gbfgetint16(fin); + int l0 = gbfgetint16(fin); if (l0 > 0) { - char first; - - first = gbfgetc(fin); + char first = gbfgetc(fin); if (first == 0) { short l1; short l2; @@ -468,9 +464,9 @@ read_poi(const int sz, const int tag) static void read_poi_list(const int sz) { - int pos, i; + int i; - pos = gbftell(fin); + int pos = gbftell(fin); #ifdef GPI_DBG PP; dbginfo("> reading poi list (-> %1$x / %1$d )\n", pos + sz); @@ -509,18 +505,14 @@ read_poi_list(const int sz) static void read_poi_group(const int sz, const int tag) { - int pos; - - pos = gbftell(fin); + int pos = gbftell(fin); #ifdef GPI_DBG PP; dbginfo("> reading poi group (-> %1$x / %1$d)\n", pos + sz); #endif if (tag == 0x80009) { - int subsz; - PP; - subsz = gbfgetint32(fin); /* ? offset to category data ? */ + int subsz = gbfgetint32(fin); /* ? offset to category data ? */ #ifdef GPI_DBG dbginfo("group sublen = %d (-> %x / %d)\n", subsz, pos + subsz + 4, pos + subsz + 4); #else @@ -553,15 +545,15 @@ static int read_tag(const char* caller, const int tag, Waypoint* wpt) { Q_UNUSED(caller); - int pos, sz, dist; + int dist; double speed; short mask; QString str; char* cstr; garmin_fs_t* gmsd; - sz = gbfgetint32(fin); - pos = gbftell(fin); + int sz = gbfgetint32(fin); + int pos = gbftell(fin); #ifdef GPI_DBG PP; @@ -762,9 +754,7 @@ read_tag(const char* caller, const int tag, Waypoint* wpt) static void write_string(const char* str, const char long_format) { - int len; - - len = strlen(str); + int len = strlen(str); if (long_format) { gbfputint32(len + 4, fout); gbfwrite("EN", 1, 2, fout); @@ -790,9 +780,7 @@ compare_strings(const QString& s1, const QString& s2) static writer_data_t* wdata_alloc() { - writer_data_t* res; - - res = (writer_data_t*) xcalloc(1, sizeof(*res)); + writer_data_t* res = (writer_data_t*) xcalloc(1, sizeof(*res)); QUEUE_INIT(&res->Q); waypt_init_bounds(&res->bds); @@ -848,7 +836,7 @@ static void wdata_check(writer_data_t* data) { queue* elem, *tmp; - double center_lat, center_lon; + double center_lon; if ((data->ct <= WAYPOINTS_PER_BLOCK) || /* avoid endless loop for points (more than WAYPOINTS_PER_BLOCK) @@ -862,7 +850,7 @@ wdata_check(writer_data_t* data) /* compute the (mean) center of current bounds */ - center_lat = center_lon = 0; + double center_lat = center_lon = 0; QUEUE_FOR_EACH(&data->Q, elem, tmp) { Waypoint* wpt = (Waypoint*) elem; center_lat += wpt->latitude; @@ -928,9 +916,7 @@ wdata_compute_size(writer_data_t* data) QUEUE_FOR_EACH(&data->Q, elem, tmp) { Waypoint* wpt = (Waypoint*) elem; - gpi_waypt_t* dt; garmin_fs_t* gmsd; - QString str; res += 12; /* tag/sz/sub-sz */ res += 19; /* poi fixed size */ @@ -939,16 +925,14 @@ wdata_compute_size(writer_data_t* data) res += 10; /* tag(4) */ } - dt = (gpi_waypt_t*) xcalloc(1, sizeof(*dt)); + gpi_waypt_t* dt = (gpi_waypt_t*) xcalloc(1, sizeof(*dt)); wpt->extra_data = dt; if (alerts) { #if NEW_STRINGS -// examine closely. - const char* pos; int pidx; if ((pidx = wpt->shortname.indexOf('@')) != -1) { - pos = CSTR(wpt->shortname.mid(pidx)); + const char* pos = CSTR(wpt->shortname.mid(pidx)); #else char* pos; if ((pos = strchr(wpt->shortname, '@'))) { @@ -984,7 +968,7 @@ wdata_compute_size(writer_data_t* data) } } - str = QString(); + QString str = QString(); if (opt_descr) { if (!wpt->description.isEmpty()) { str = wpt->description; @@ -1096,18 +1080,17 @@ wdata_write(const writer_data_t* data) gbfputc(data->alert, fout); QUEUE_FOR_EACH(&data->Q, elem, tmp) { - QString str; - int s0, s1; + int s1; Waypoint* wpt = (Waypoint*)elem; gpi_waypt_t* dt = (gpi_waypt_t*) wpt->extra_data; - str = wpt->description; + QString str = wpt->description; if (str.isEmpty()) { str = wpt->notes; } gbfputint32(0x80002, fout); - s0 = s1 = 19 + strlen(STRFROMUNICODE(wpt->shortname)); + int s0 = s1 = 19 + strlen(STRFROMUNICODE(wpt->shortname)); if (! opt_hide_bitmap) { s0 += 10; /* tag(4) */ } @@ -1224,9 +1207,7 @@ skip_empty_block: static void write_category(const char*, const unsigned char* image, const int image_sz) { - int sz; - - sz = wdata_compute_size(wdata); + int sz = wdata_compute_size(wdata); sz += 8; /* string header */ sz += strlen(STRFROMUNICODE(QString::fromUtf8(opt_cat))); @@ -1284,7 +1265,6 @@ write_header() static void enum_waypt_cb(const Waypoint* ref) { - Waypoint* wpt; queue* elem, *tmp; QUEUE_FOR_EACH(&wdata->Q, elem, tmp) { @@ -1300,7 +1280,7 @@ enum_waypt_cb(const Waypoint* ref) } } - wpt = new Waypoint(*ref); + Waypoint* wpt = new Waypoint(*ref); if (*opt_unique == '1') { wpt->shortname = mkshort(short_h, wpt->shortname); @@ -1313,7 +1293,6 @@ enum_waypt_cb(const Waypoint* ref) static void load_bitmap_from_file(const char* fname, unsigned char** data, int* data_sz) { - gbfile* f; int i, sz; int dest_bpp; int src_line_sz, dest_line_sz; @@ -1322,7 +1301,7 @@ load_bitmap_from_file(const char* fname, unsigned char** data, int* data_sz) gpi_bitmap_header_t* dest_h; unsigned char* ptr; - f = gbfopen_le(fname, "rb", MYNAME); + gbfile* f = gbfopen_le(fname, "rb", MYNAME); is_fatal(gbfgetint16(f) != 0x4d42, MYNAME ": No BMP image."); /* read a standard bmp file header */ @@ -1435,8 +1414,7 @@ load_bitmap_from_file(const char* fname, unsigned char** data, int* data_sz) unsigned char* p = ptr; for (j = 0; j < src_h.width; j++) { - int color; - color = (int32_t)gbfgetint16(f) | (gbfgetc(f) << 16); + int color = (int32_t)gbfgetint16(f) | (gbfgetc(f) << 16); le_write32(p, color); p += 4; } diff --git a/garmin_tables.cc b/garmin_tables.cc index cea24539e..a8241bb1a 100644 --- a/garmin_tables.cc +++ b/garmin_tables.cc @@ -775,7 +775,6 @@ int gt_find_icon_number_from_desc(const QString& desc, garmin_formats_e garmin_f static int find_flag = 0; icon_mapping_t* i; int def_icon = DEFAULT_ICON_VALUE; - int n; if (desc.isNull()) { return def_icon; @@ -785,7 +784,7 @@ int gt_find_icon_number_from_desc(const QString& desc, garmin_formats_e garmin_f * If we were given a numeric icon number as a description * (i.e. 8255), just return that. */ - n = desc.toInt(); + int n = desc.toInt(); if (n) { return n; } @@ -899,7 +898,6 @@ gt_get_icao_cc(const QString& country, const QString& shortname) gt_country_code_t* x = >_country_codes[0]; if (country.isEmpty()) { - const char* test; if (shortname == nullptr) { return nullptr; } @@ -913,7 +911,7 @@ gt_get_icao_cc(const QString& country, const QString& shortname) default: return nullptr; } - test = gt_get_icao_country(res); + const char* test = gt_get_icao_country(res); if (test != nullptr) { return res; } else { @@ -989,9 +987,7 @@ gt_get_mps_grid_longname(const grid_type grid, const char* module) const char* gt_get_mps_datum_name(const int datum_index) { - const char* result; - - result = GPS_Math_Get_Datum_Name(datum_index); + const char* result = GPS_Math_Get_Datum_Name(datum_index); for (datum_mapping_t* d = gt_mps_datum_names; (d->jeeps_name); d++) if (QString::compare(result, d->jeeps_name, Qt::CaseInsensitive) == 0) { @@ -1004,7 +1000,6 @@ gt_get_mps_datum_name(const int datum_index) int gt_lookup_datum_index(const char* datum_str, const QString& module) { - int result; const char* name = datum_str; for (datum_mapping_t* d = gt_mps_datum_names; (d->jeeps_name); d++) { @@ -1014,7 +1009,7 @@ gt_lookup_datum_index(const char* datum_str, const QString& module) } } - result = GPS_Lookup_Datum_Index(name); + int result = GPS_Lookup_Datum_Index(name); // Didn't get a hit? Try again after modifying the lookup. if (result < 0) { diff --git a/garmin_txt.cc b/garmin_txt.cc index 96585c46f..685aa4b0e 100644 --- a/garmin_txt.cc +++ b/garmin_txt.cc @@ -174,16 +174,13 @@ get_option_val(const char* option, const char* def) static void init_date_and_time_format() { - const char* f; - const char* c; - - f = get_option_val(opt_date_format, DEFAULT_DATE_FORMAT); + const char* f = get_option_val(opt_date_format, DEFAULT_DATE_FORMAT); date_time_format = convert_human_date_format(f); date_time_format = xstrappend(date_time_format, " "); f = get_option_val(opt_time_format, DEFAULT_TIME_FORMAT); - c = convert_human_time_format(f); + const char* c = convert_human_time_format(f); date_time_format = xstrappend(date_time_format, c); xfree((void*) c); } @@ -207,11 +204,8 @@ convert_datum(const Waypoint* wpt, double* dest_lat, double* dest_lon) static void enum_waypt_cb(const Waypoint* wpt) { - garmin_fs_p gmsd; - int wpt_class; - - gmsd = GMSD_FIND(wpt); - wpt_class = GMSD_GET(wpt_class, 0); + garmin_fs_p gmsd = GMSD_FIND(wpt); + int wpt_class = GMSD_GET(wpt_class, 0); if (wpt_class < 0x80) { if (gtxt_flags.enum_waypoints) { /* enumerate only */ waypoints++; @@ -283,9 +277,7 @@ print_position(const Waypoint* wpt) { int valid = 1; double lat, lon, north, east; - char latsig, lonsig; - double latmin, lonmin, latsec, lonsec; - int latint, lonint, zone; + int zone; char map[3], zonec; convert_datum(wpt, &lat, &lon); @@ -296,14 +288,14 @@ print_position(const Waypoint* wpt) /* !ToDo! generate common code for calculating of degrees, minutes and seconds */ /* ----------------------------------------------------------------------------*/ - latsig = lat < 0 ? 'S':'N'; - lonsig = lon < 0 ? 'W':'E'; - latint = abs((int) lat); - lonint = abs((int) lon); - latmin = 60.0 * (fabs(lat) - latint); - lonmin = 60.0 * (fabs(lon) - lonint); - latsec = 60.0 * (latmin - floor(latmin)); - lonsec = 60.0 * (lonmin - floor(lonmin)); + char latsig = lat < 0 ? 'S':'N'; + char lonsig = lon < 0 ? 'W':'E'; + int latint = abs((int) lat); + int lonint = abs((int) lon); + double latmin = 60.0 * (fabs(lat) - latint); + double lonmin = 60.0 * (fabs(lon) - lonint); + double latsec = 60.0 * (latmin - floor(latmin)); + double lonsec = 60.0 * (lonmin - floor(lonmin)); switch (grid_index) { @@ -396,14 +388,13 @@ print_date_and_time(const time_t time, const int time_only) static void print_categories(uint16_t categories) { - int count; char* c; if (categories == 0) { return; } - count = 0; + int count = 0; for (int i = 0; i < 16; i++) { if ((categories & 1) != 0) { if (global_opts.inifile != nullptr) { @@ -432,8 +423,7 @@ static void print_course(const Waypoint* A, const Waypoint* B) /* seems to be okay */ { if ((A != nullptr) && (B != nullptr) && (A != B)) { - int course; - course = si_round(waypt_course(A, B)); + int course = si_round(waypt_course(A, B)); gbfprintf(fout, "%d%c true", course, kDegreeSymbol); } } @@ -476,7 +466,6 @@ print_distance(const double distance, const int no_scale, const int with_tab, co static void print_speed(double* distance, time_t* time) { - int idist; double dist = *distance; const char* unit; @@ -486,7 +475,7 @@ print_speed(double* distance, time_t* time) } else { unit = "kph"; } - idist = si_round(dist); + int idist = si_round(dist); if ((*time != 0) && (idist > 0)) { double speed = MPS_TO_KPH(dist / (double)*time); @@ -518,9 +507,7 @@ print_temperature(const float temperature) static void print_string(const char* fmt, const char* string) { - char* buff; - - buff = xstrdup(string); + char* buff = xstrdup(string); /* remove unwanted characters from source string */ for (char* c = buff; *c; c++) { if (iscntrl(*c)) { @@ -543,23 +530,17 @@ print_string(const char* fmt, const QString& string) static void write_waypt(const Waypoint* wpt) { - unsigned char wpt_class; - garmin_fs_p gmsd; const char* wpt_type; - const char* dspl_mode; - const char* country; - double x; - int i, icon; - gmsd = GMSD_FIND(wpt); + garmin_fs_p gmsd = GMSD_FIND(wpt); - i = GMSD_GET(display, 0); + int i = GMSD_GET(display, 0); if (i > GT_DISPLAY_MODE_MAX) { i = 0; } - dspl_mode = gt_display_mode_names[i]; + const char* dspl_mode = gt_display_mode_names[i]; - wpt_class = GMSD_GET(wpt_class, 0); + unsigned char wpt_class = GMSD_GET(wpt_class, 0); if (wpt_class <= gt_waypt_class_map_line) { wpt_type = gt_waypt_class_names[wpt_class]; } else { @@ -589,7 +570,7 @@ write_waypt(const Waypoint* wpt) } gbfprintf(fout, "\t"); - x = WAYPT_GET(wpt, depth, unknown_alt); + double x = WAYPT_GET(wpt, depth, unknown_alt); if (x != unknown_alt) { print_distance(x, 1, 0, 1); } @@ -609,7 +590,7 @@ write_waypt(const Waypoint* wpt) gbfprintf(fout, "Unknown\t"); /* Color is fixed: Unknown */ - icon = GMSD_GET(icon, -1); + int icon = GMSD_GET(icon, -1); if (icon == -1) { icon = gt_find_icon_number_from_desc(wpt->icon_descr, GDB); } @@ -618,7 +599,7 @@ write_waypt(const Waypoint* wpt) print_string("%s\t", GMSD_GET(facility, "")); print_string("%s\t", GMSD_GET(city, "")); print_string("%s\t", GMSD_GET(state, "")); - country = gt_get_icao_country(GMSD_GET(cc, "")); + const char* country = gt_get_icao_country(GMSD_GET(cc, "")); print_string("%s\t", (country != nullptr) ? country : ""); print_date_and_time(wpt->GetCreationTime().toTime_t(), 0); if (wpt->HasUrlLink()) { @@ -717,7 +698,7 @@ track_disp_wpt_cb(const Waypoint* wpt) { const Waypoint* prev = cur_info->prev_wpt; time_t delta; - double dist, depth; + double dist; gbfprintf(fout, "Trackpoint\t"); @@ -728,16 +709,15 @@ track_disp_wpt_cb(const Waypoint* wpt) } gbfprintf(fout, "\t"); - depth = WAYPT_GET(wpt, depth, unknown_alt); + double depth = WAYPT_GET(wpt, depth, unknown_alt); if (depth != unknown_alt) { print_distance(depth, 1, 0, 1); } if (prev != nullptr) { - float temp; gbfprintf(fout, "\t"); delta = wpt->GetCreationTime().toTime_t() - prev->GetCreationTime().toTime_t(); - temp = WAYPT_GET(wpt, temperature, -999); + float temp = WAYPT_GET(wpt, temperature, -999); if (temp != -999) { print_temperature(temp); } @@ -760,8 +740,6 @@ track_disp_wpt_cb(const Waypoint* wpt) static void garmin_txt_wr_init(const QString& fname) { - const char* grid_str; - memset(>xt_flags, 0, sizeof(gtxt_flags)); fout = gbfopen(fname, "wb", MYNAME); @@ -775,7 +753,7 @@ garmin_txt_wr_init(const QString& fname) } datum_str = get_option_val(opt_datum, nullptr); - grid_str = get_option_val(opt_grid, nullptr); + const char* grid_str = get_option_val(opt_grid, nullptr); grid_index = grid_lat_lon_dmm; if (grid_str != nullptr) { @@ -823,17 +801,16 @@ garmin_txt_wr_deinit() static void garmin_txt_write() { - char* grid_str, *c; - const char* datum_str; + char* c; - grid_str = xstrdup(gt_get_mps_grid_longname(grid_index, MYNAME)); + char* grid_str = xstrdup(gt_get_mps_grid_longname(grid_index, MYNAME)); while ((c = strchr(grid_str, '*'))) { *c = kDegreeSymbol; /* degree sign */ } gbfprintf(fout, "Grid\t%s\r\n", grid_str); xfree(grid_str); - datum_str = gt_get_mps_datum_name(datum_index); + const char* datum_str = gt_get_mps_datum_name(datum_index); gbfprintf(fout, "Datum\t%s\r\n\r\n", datum_str); waypoints = 0; @@ -903,15 +880,14 @@ static int parse_date_and_time(char* str, time_t* value) { struct tm tm; - char* cerr, *cin; memset(&tm, 0, sizeof(tm)); - cin = lrtrim(str); + char* cin = lrtrim(str); if (*cin == '\0') { return 0; } - cerr = strptime(cin, date_time_format, &tm); + char* cerr = strptime(cin, date_time_format, &tm); if (cerr == nullptr) { cerr = strptime(cin, "%m/%d/%Y %I:%M:%S %p", &tm); is_fatal(cerr == nullptr, MYNAME ": Invalid date or/and time \"%s\" at line %d!", cin, current_line); @@ -930,14 +906,14 @@ parse_categories(const char* str) char buff[256]; uint16_t val; uint16_t res = 0; - char* cin, *cx; + char* cx; if (*str == '\0') { return 0; } strncpy(buff, str, sizeof(buff)); - cin = lrtrim(buff); + char* cin = lrtrim(buff); if (*cin == '\0') { return 0; } @@ -1025,9 +1001,6 @@ parse_display(const char* str, int* val) static void bind_fields(const header_type ht) { - int i; - char* fields, *c; - is_fatal((grid_index < 0) || (datum_index < 0), MYNAME ": Incomplete or invalid file header!"); if (header_ct[unknown_header] <= 0) { @@ -1037,23 +1010,21 @@ bind_fields(const header_type ht) /* make a copy of headers[ht], uppercase, replace "\t" with "\0" */ - i = strlen(headers[ht]); - fields = (char*) xmalloc(i + 2); + int i = strlen(headers[ht]); + char* fields = (char*) xmalloc(i + 2); strcpy(fields, headers[ht]); strcat(fields, "\t"); - c = strupper(fields); + char* c = strupper(fields); while ((c = strchr(c, '\t'))) { *c++ = '\0'; } for (i = 0; i < header_ct[unknown_header]; i++) { - char* name; - int field_no; - name = header_lines[ht][i] = header_lines[unknown_header][i]; + char* name = header_lines[ht][i] = header_lines[unknown_header][i]; header_lines[unknown_header][i] = nullptr; c = fields; - field_no = 1; + int field_no = 1; while (*c) { if (strcmp(c, name) == 0) { header_fields[ht][i] = field_no; @@ -1107,11 +1078,10 @@ parse_waypoint() { char* str; int column = -1; - Waypoint* wpt; bind_fields(waypt_header); - wpt = new Waypoint; + Waypoint* wpt = new Waypoint; garmin_fs_p gmsd = garmin_fs_alloc(-1); fs_chain_add(&wpt->fs, (format_specific_data*) gmsd); @@ -1210,9 +1180,8 @@ parse_route_header() { char* str; int column = -1; - route_head* rte; - rte = route_head_alloc(); + route_head* rte = route_head_alloc(); bind_fields(route_header); while ((str = csv_lineparse(nullptr, "\t", "", column++))) { @@ -1235,10 +1204,9 @@ parse_track_header() { char* str; int column = -1; - route_head* trk; bind_fields(track_header); - trk = route_head_alloc(); + route_head* trk = route_head_alloc(); while ((str = csv_lineparse(nullptr, "\t", "", column++))) { int field_no = header_fields[track_header][column]; switch (field_no) { @@ -1284,20 +1252,18 @@ parse_track_waypoint() { char* str; int column = -1; - Waypoint* wpt; bind_fields(trkpt_header); - wpt = new Waypoint; + Waypoint* wpt = new Waypoint; while ((str = csv_lineparse(nullptr, "\t", "", column++))) { - int field_no; double x; if (! *str) { continue; } - field_no = header_fields[trkpt_header][column]; + int field_no = header_fields[trkpt_header][column]; switch (field_no) { case 1: parse_coordinates(str, datum_index, grid_index, @@ -1372,13 +1338,11 @@ garmin_txt_read() current_line = 0; while ((buff = gbfgetstr(fin))) { - char* cin; - if ((current_line++ == 0) && fin->unicode) { cet_convert_init(CET_CHARSET_UTF8, 1); } - cin = lrtrim(buff); + char* cin = lrtrim(buff); if (*cin == '\0') { continue; } diff --git a/garmin_xt.cc b/garmin_xt.cc index 58f30eb46..61097c0d8 100644 --- a/garmin_xt.cc +++ b/garmin_xt.cc @@ -152,9 +152,9 @@ format_garmin_xt_rd_st_attrs(char* p_trk_name, uint8_t* p_track_color) static void format_garmin_xt_decrypt_trk_blk(int Count, uint8_t TrackBlock[]) { - uint8_t i,j = 12; + uint8_t j = 12; while (j<(Count-1)) { - for (i = j; i < Count; i++) { + for (uint8_t i = j; i < Count; i++) { TrackBlock[i] = TrackBlock[i] >> 1; if (i<(Count)) { TrackBlock[i] = TrackBlock[i] + (TrackBlock[i+1] % 2) * 128; @@ -170,10 +170,8 @@ format_garmin_xt_decrypt_trk_blk(int Count, uint8_t TrackBlock[]) static void format_garmin_xt_decomp_trk_blk(uint8_t ii, uint8_t TrackBlock[], double* Ele, double* Lat, double* Lon, uint32_t* Time) { - uint16_t PrevEleW; - //printf("%d %d %d %d %d %d\n", TrackBlock[0], TrackBlock[1], TrackBlock[2], TrackBlock[3], TrackBlock[4], TrackBlock[5]); - PrevEleW = TrackBlock[(ii - 1) * 12 + 1 ]; + uint16_t PrevEleW = TrackBlock[(ii - 1) * 12 + 1 ]; PrevEleW = PrevEleW << 8; PrevEleW = PrevEleW + TrackBlock[(ii - 1) * 12 ]; *Ele = (double)PrevEleW * GARMIN_XT_ELE - 1500; @@ -216,9 +214,7 @@ format_garmin_xt_decomp_trk_blk(uint8_t ii, uint8_t TrackBlock[], double* Ele, d static void format_garmin_xt_decomp_last_ele(uint8_t ii, double* PrevEle, uint8_t TrackBlock[]) { - uint16_t PrevEleW; - - PrevEleW = TrackBlock[ii - 1]; + uint16_t PrevEleW = TrackBlock[ii - 1]; PrevEleW = PrevEleW << 8; PrevEleW = PrevEleW + TrackBlock[ii - 2]; *PrevEle = (double)PrevEleW * GARMIN_XT_ELE - 1500; @@ -233,11 +229,9 @@ format_garmin_xt_proc_strk() int Count = 0; // Used to obtain number of read bytes int TracksCompleted = 0; // Number of processed tracks uint8_t TrackBlock[STRK_BLOCK_SIZE + 1]; // File Block - uint8_t ii; // temp variable double Lat = 0, Lon = 0; // wpt data double PrevLat = 0, PrevLon = 0, PrevEle = 0; // wpt data uint32_t Time = 0; // wpt data - int FirstCoo; uint8_t trk_color = 0xff; // Skip 12 bytes from the BOF @@ -251,15 +245,13 @@ format_garmin_xt_proc_strk() // Process all tracks one by one while ((TracksCompleted < NumberOfTracks) && (!gbfeof(fin))) { - route_head* tmp_track; Waypoint* wpt; - char* trk_name; - trk_name = (char*) xmalloc(30); + char* trk_name = (char*) xmalloc(30); // Generate Track Header uint16_t trackbytes = format_garmin_xt_rd_st_attrs(trk_name, &trk_color) - 50; // Bytes in track - tmp_track = route_head_alloc(); + route_head* tmp_track = route_head_alloc(); // update track color tmp_track->line_color.bbggrr = colors[trk_color]; tmp_track->line_color.opacity = 255; @@ -269,7 +261,7 @@ format_garmin_xt_proc_strk() track_add_head(tmp_track); // This is the 1st coordinate of the track - FirstCoo = TRUE; + int FirstCoo = TRUE; while (trackbytes>0) { if (trackbytes>=STRK_BLOCK_SIZE) { Count = gbfread(&TrackBlock, DATABLOCKSIZE, STRK_BLOCK_SIZE, fin); @@ -283,7 +275,7 @@ format_garmin_xt_proc_strk() format_garmin_xt_decrypt_trk_blk(Count, TrackBlock); // process each track point in the loaded TrackBlock - for (ii=1; ii <= ((Count-1) / 12); ii++) { + for (uint8_t ii = 1; ii <= ((Count-1) / 12); ii++) { // decompose loaded track block part (track point) format_garmin_xt_decomp_trk_blk(ii, TrackBlock, &PrevEle, &Lat, &Lon, &Time); @@ -334,10 +326,8 @@ format_garmin_xt_proc_strk() static void format_garmin_xt_proc_atrk() { - Waypoint* wpt; int method = 0; unsigned char buf[3]; - int32_t num_trackpoints; // get the option for the processing the track name if (opt_trk_header) { @@ -355,7 +345,7 @@ format_garmin_xt_proc_atrk() // We think the word at offset 0xc is the trackpoint count. gbfseek(fin, 12, SEEK_SET); - num_trackpoints = gbfgetuint32(fin); + int32_t num_trackpoints = gbfgetuint32(fin); while (num_trackpoints--) { uint16_t block = gbfgetuint16(fin); @@ -383,7 +373,7 @@ format_garmin_xt_proc_atrk() double AltF = (double)uu * GARMIN_XT_ELE - 1500; //create new waypoint - wpt = new Waypoint; + Waypoint* wpt = new Waypoint; //populate wpt; wpt->latitude = LatF*180/16777216; /* Degrees */ diff --git a/gbfile.cc b/gbfile.cc index 83efde16e..bc5f36abf 100644 --- a/gbfile.cc +++ b/gbfile.cc @@ -113,14 +113,12 @@ gzapi_close(gbfile* self) static int gzapi_seek(gbfile* self, int32_t offset, int whence) { - int result; - assert(whence != SEEK_END); if ((whence == SEEK_CUR) && (self->back != -1)) { offset--; } - result = gzseek(self->handle.gz, offset, whence); + int result = gzseek(self->handle.gz, offset, whence); self->back = -1; if (result < 0) { @@ -156,9 +154,8 @@ gzapi_read(void* buf, const gbsize_t size, const gbsize_t members, gbfile* self) if ((result < 0) || ((gbsize_t)result < members)) { int errnum; - const char* errtxt; - errtxt = gzerror(self->handle.gz, &errnum); + const char* errtxt = gzerror(self->handle.gz, &errnum); /* Workaround for zlib bug: buffer error on empty files */ if ((errnum == Z_BUF_ERROR) && (gztell(self->handle.gz) == 0)) { @@ -186,9 +183,7 @@ gzapi_flush(gbfile* self) static gbsize_t gzapi_tell(gbfile* self) { - gbsize_t result; - - result = gztell(self->handle.gz); + gbsize_t result = gztell(self->handle.gz); if (self->back != -1) { result--; } @@ -273,14 +268,13 @@ stdapi_close(gbfile* self) static int stdapi_seek(gbfile* self, int32_t offset, int whence) { - int result; gbsize_t pos = 0; if (whence != SEEK_SET) { pos = ftell(self->handle.std); } - result = fseek(self->handle.std, offset, whence); + int result = fseek(self->handle.std, offset, whence); if (result != 0) { switch (whence) { case SEEK_CUR: @@ -408,13 +402,12 @@ memapi_seek(gbfile* self, int32_t offset, int whence) static gbsize_t memapi_read(void* buf, const gbsize_t size, const gbsize_t members, gbfile* self) { - gbsize_t count; gbsize_t result = (self->memlen - self->mempos) / size; if (result > members) { result = members; } - count = result * size; + gbsize_t count = result * size; if (count) { memcpy(buf, self->handle.mem + self->mempos, count); self->mempos += count; @@ -426,14 +419,12 @@ memapi_read(void* buf, const gbsize_t size, const gbsize_t members, gbfile* self static gbsize_t memapi_write(const void* buf, const gbsize_t size, const gbsize_t members, gbfile* self) { - gbsize_t count; - if ((size == 0) && (members == 0)) { /* truncate stream */ self->memlen = self->mempos; return 0; } - count = size * members; + gbsize_t count = size * members; if (self->mempos + count > self->memsz) { self->memsz = ((self->mempos + count + 4095) / 4096) * 4096; @@ -503,11 +494,7 @@ memapi_error(gbfile* self) gbfile* gbfopen(const QString& filename, const char* mode, const char* module) { - gbfile* file; - const char* m; - int len; - - file = (gbfile*) xcalloc(1, sizeof(*file)); + gbfile* file = (gbfile*) xcalloc(1, sizeof(*file)); file->module = xstrdup(module); file->mode = 'r'; // default @@ -515,7 +502,7 @@ gbfopen(const QString& filename, const char* mode, const char* module) file->back = -1; file->memapi = (filename == nullptr); - for (m = mode; *m; m++) { + for (const char* m = mode; *m; m++) { switch (tolower(*m)) { case 'r': file->mode = 'r'; @@ -549,7 +536,7 @@ gbfopen(const QString& filename, const char* mode, const char* module) file->is_pipe = (filename == "-"); /* Do we have a '.gz' extension in the filename ? */ - len = strlen(file->name); + int len = strlen(file->name); if ((len > 3) && (case_ignore_strcmp(&file->name[len-3], ".gz") == 0)) { #if !ZLIB_INHIBITED /* force gzipped files on output */ @@ -611,9 +598,7 @@ gbfopen(const QString& filename, const char* mode, const char* module) gbfile* gbfopen_be(const QString& filename, const char* mode, const char* module) { - gbfile* result; - - result = gbfopen(filename, mode, module); + gbfile* result = gbfopen(filename, mode, module); result->big_endian = 1; return result; @@ -767,10 +752,9 @@ int gbfprintf(gbfile* file, const char* format, ...) { va_list args; - int result; va_start(args, format); - result = gbvfprintf(file, format, args); + int result = gbvfprintf(file, format, args); va_end(args); return result; @@ -811,9 +795,7 @@ gbfputs(const QString& s, gbfile* file) int gbfwrite(const void* buf, const gbsize_t size, const gbsize_t members, gbfile* file) { - unsigned int result; - - result = file->filewrite(buf, size, members, file); + unsigned int result = file->filewrite(buf, size, members, file); if (result != members) { fatal("%s: Could not write %lld bytes to %s (result %d)!\n", file->module, @@ -988,7 +970,6 @@ gbfgetflt(gbfile* file) char* gbfgetcstr_old(gbfile* file) { - char* result; int len = 0; char* str = file->buff; @@ -1007,7 +988,7 @@ gbfgetcstr_old(gbfile* file) len++; } - result = (char*) xmalloc(len + 1); + char* result = (char*) xmalloc(len + 1); if (len > 0) { memcpy(result, str, len); } @@ -1049,14 +1030,12 @@ gbfgetucs2str(gbfile* file) for (;;) { char buff[8]; - int clen; - int c0, c1; - c0 = gbfgetc(file); + int c0 = gbfgetc(file); if ((c0 == EOF) && (len == 0)) { return nullptr; } - c1 = gbfgetc(file); + int c1 = gbfgetc(file); if ((c1 == EOF) && (len == 0)) { return nullptr; } @@ -1091,7 +1070,7 @@ gbfgetucs2str(gbfile* file) break; } - clen = cet_ucs4_to_utf8(buff, sizeof(buff), c0); + int clen = cet_ucs4_to_utf8(buff, sizeof(buff), c0); if (clen < 1) { Warning() << "Malformed UCS character" << c0 << "found."; return nullptr; @@ -1141,10 +1120,9 @@ gbfgetstr(gbfile* file) } else if (c == '\n') { break; } else if (((c == 0xFE) || (c == 0xFF)) && (! file->unicode_checked)) { - int cx; int c1 = gbfgetc(file); if (c1 != EOF) { - cx = c | (c1 << 8); + int cx = c | (c1 << 8); if (cx == 0xFEFF) { file->unicode = 1; file->big_endian = 0; diff --git a/gbser.cc b/gbser.cc index 77388a269..046737ba5 100644 --- a/gbser.cc +++ b/gbser.cc @@ -69,9 +69,8 @@ static int parity_letter(char c) int gbser_setup(void* handle, const char* spec) { unsigned arg[] = { 4800, 8, 0, 1 }; - unsigned int ap; - for (ap = 0; ap < sizeof(arg) / sizeof(arg[0]); ap++) { + for (unsigned int ap = 0; ap < sizeof(arg) / sizeof(arg[0]); ap++) { unsigned t = 0; int pl; while (isspace(*spec)) { @@ -160,9 +159,8 @@ int gbser_read_wait(void* handle, void* buf, unsigned len, unsigned ms) int gbser_readc(void* handle) { unsigned char buf; - int rc; - rc = gbser_read(handle, &buf, 1); + int rc = gbser_read(handle, &buf, 1); if (rc > 0) { return buf; } else if (rc == 0) { @@ -178,9 +176,8 @@ int gbser_readc(void* handle) int gbser_readc_wait(void* handle, unsigned ms) { unsigned char buf; - int rc; - rc = gbser_read_wait(handle, &buf, 1, ms); + int rc = gbser_read_wait(handle, &buf, 1, ms); if (rc > 0) { return buf; } else if (rc == 0) { diff --git a/gbser_win.cc b/gbser_win.cc index 58b9b0efc..371ccdc98 100644 --- a/gbser_win.cc +++ b/gbser_win.cc @@ -155,9 +155,8 @@ fix_win_serial_name_r(const char* comname, char* obuf, size_t len) ) { strncpy(obuf, comname, len); } else { - size_t l; snprintf(obuf, len, DEV_PREFIX "%s", comname); - l = strlen(obuf); + size_t l = strlen(obuf); if (obuf[l - 1] == ':') { obuf[l - 1] = '\0'; } @@ -180,7 +179,6 @@ const char* fix_win_serial_name(const char* comname) */ void* gbser_init(const char* port_name) { - HANDLE comport; gbser_handle* h = (gbser_handle*) xcalloc(1, sizeof(*h)); const char* xname = fix_win_serial_name(port_name); @@ -188,8 +186,8 @@ void* gbser_init(const char* port_name) h->magic = MYMAGIC; - comport = CreateFileA(xname, GENERIC_READ | GENERIC_WRITE, - 0, NULL, OPEN_EXISTING, 0, NULL); + HANDLE comport = CreateFileA(xname, GENERIC_READ | GENERIC_WRITE, + 0, NULL, OPEN_EXISTING, 0, NULL); if (comport == INVALID_HANDLE_VALUE) { goto failed; @@ -330,8 +328,7 @@ int gbser__fill_buffer(void* handle, unsigned want, unsigned* ms) } } else { hp_time tv; - double time_left; - DWORD err, nread; + DWORD nread; get_time(&tv); if (rc = set_rx_timeout(h, *ms), rc) { return rc; @@ -339,13 +336,13 @@ int gbser__fill_buffer(void* handle, unsigned want, unsigned* ms) if (!ReadFile(h->comport, h->inbuf + h->inbuf_used, want - h->inbuf_used, &nread, NULL)) { - err = GetLastError(); + DWORD err = GetLastError(); if (err != ERROR_COUNTER_TIMEOUT && err != ERROR_TIMEOUT) { return gbser_ERROR; } } h->inbuf_used += nread; - time_left = *ms - elapsed(&tv); + double time_left = *ms - elapsed(&tv); *ms = time_left < 0 ? 0 : (unsigned) time_left; } @@ -446,11 +443,10 @@ int gbser_read_line(void* handle, void* buf, bp[pos] = '\0'; for (;;) { signed time_left = ms - elapsed(&tv); - int c; if (time_left <= 0) { return gbser_TIMEOUT; } - c = gbser_readc_wait(handle, time_left); + int c = gbser_readc_wait(handle, time_left); if (c == gbser_ERROR) { return c; } else if (c == eol) { diff --git a/gdb.cc b/gdb.cc index 16d330b22..a814c7e24 100644 --- a/gdb.cc +++ b/gdb.cc @@ -266,9 +266,8 @@ gdb_fread_strlist() { // char* res = NULL; QString res; - int count; - count = FREAD_i32; + int count = FREAD_i32; while (count > 0) { QString str = fread_cstr(); @@ -308,8 +307,7 @@ gdb_find_wayptq(const queue* Q, const Waypoint* wpt, const char exact) static Waypoint* gdb_reader_find_waypt(const Waypoint* wpt, const char exact) { - Waypoint* res; - res = gdb_find_wayptq(&wayptq_in, wpt, exact); + Waypoint* res = gdb_find_wayptq(&wayptq_in, wpt, exact); if (res == nullptr) { res = gdb_find_wayptq(&wayptq_in_hidden, wpt, exact); } @@ -319,13 +317,8 @@ gdb_reader_find_waypt(const Waypoint* wpt, const char exact) static Waypoint* gdb_add_route_waypt(route_head* rte, Waypoint* ref, const int wpt_class) { - Waypoint* tmp, *res; - int turn_point; - - tmp = gdb_reader_find_waypt(ref, 1); + Waypoint* tmp = gdb_reader_find_waypt(ref, 1); if (tmp == nullptr) { - double dist; - tmp = find_waypt_by_name(ref->shortname); if (tmp == nullptr) { route_add_wpt(rte, ref); @@ -335,9 +328,9 @@ gdb_add_route_waypt(route_head* rte, Waypoint* ref, const int wpt_class) /* At this point we have found a waypoint with same name, but probably from another data stream. Check coordinates! */ - dist = radtometers(gcdist( - RAD(ref->latitude), RAD(ref->longitude), - RAD(tmp->latitude), RAD(tmp->longitude))); + double dist = radtometers(gcdist( + RAD(ref->latitude), RAD(ref->longitude), + RAD(tmp->latitude), RAD(tmp->longitude))); if (fabs(dist) > 100) { warning(MYNAME ": Route point mismatch!\n"); @@ -348,8 +341,8 @@ gdb_add_route_waypt(route_head* rte, Waypoint* ref, const int wpt_class) } } - res = nullptr; - turn_point = (gdb_roadbook && (wpt_class > gt_waypt_class_map_point) && !tmp->description.isEmpty()); + Waypoint* res = nullptr; + int turn_point = (gdb_roadbook && (wpt_class > gt_waypt_class_map_point) && !tmp->description.isEmpty()); if (turn_point || (gdb_via == 0) || (wpt_class < gt_waypt_class_map_point)) { res = new Waypoint(*tmp); route_add_wpt(rte, res); @@ -429,7 +422,6 @@ static void read_file_header() { char buf[128]; - int i, reclen; /* We are beginning with a simple binary read. @@ -444,9 +436,9 @@ read_file_header() */ is_fatal(strcmp(buf, "MsRcf") != 0, MYNAME ": Invalid file \"%s\"!", fin->name); - reclen = FREAD_i32; + int reclen = FREAD_i32; Q_UNUSED(reclen); - i = FREAD_STR(buf); + int i = FREAD_STR(buf); Q_UNUSED(i); is_fatal(buf[0] != 'D', MYNAME ": Invalid file \"%s\"!", fin->name); @@ -627,7 +619,6 @@ read_waypoint(gt_waypt_classes_e* waypt_class_out) res->description = l.url_; } } else { // if (gdb_ver >= GDB_VER_3) - int url_ct; waypt_flag = 0; @@ -636,7 +627,7 @@ read_waypoint(gt_waypt_classes_e* waypt_class_out) FREAD(buf, 5); /* instruction depended */ res->description = FREAD_CSTR_AS_QSTR; /* instruction */ - url_ct = FREAD_i32; + int url_ct = FREAD_i32; for (int i = url_ct; (i); i--) { QString str = FREAD_CSTR_AS_QSTR; if (!str.isEmpty()) { @@ -731,15 +722,13 @@ read_waypoint(gt_waypt_classes_e* waypt_class_out) static route_head* read_route() { - route_head* rte; - int points, warnings, links; char buf[128]; bounds bounds; rte_ct++; - warnings = 0; + int warnings = 0; - rte = route_head_alloc(); + route_head* rte = route_head_alloc(); rte->rte_name = fread_cstr(); FREAD(buf, 1); /* display/autoname - 1 byte */ @@ -758,8 +747,8 @@ read_route() } } - links = 0; - points = FREAD_i32; + int links = 0; + int points = FREAD_i32; #if GDB_DEBUG DBG(GDB_DBG_RTE, 1) @@ -768,17 +757,13 @@ read_route() #endif for (int i = 0; i < points; i++) { - int wpt_class; char buf[128]; - garmin_ilink_t* il_root, *il_anchor; - Waypoint* wpt; - - wpt = new Waypoint; + Waypoint* wpt = new Waypoint; rtept_ct++; wpt->shortname = fread_cstr(); /* shortname */ - wpt_class = FREAD_i32; /* waypoint class */ + int wpt_class = FREAD_i32; /* waypoint class */ FREAD_STR(buf); /* country code */ FREAD(buf, 18 + 4); /* subclass part 1-3 / unknown */ @@ -806,8 +791,8 @@ read_route() } links = FREAD_i32; - il_anchor = nullptr; - il_root = nullptr; + garmin_ilink_t* il_anchor = nullptr; + garmin_ilink_t* il_root = nullptr; #if GDB_DEBUG DBG(GDB_DBG_RTE, links) printf(MYNAME "-rte_pt \"%s\" (%d): %d interlink step(s)\n", @@ -944,22 +929,19 @@ read_route() static route_head* read_track() { - route_head* res; - int points; char dummy; - int color_idx; trk_ct++; - res = route_head_alloc(); + route_head* res = route_head_alloc(); res->rte_name = fread_cstr(); // res->rte_num = trk_ct; FREAD(&dummy, 1); /* display - 1 byte */ - color_idx = FREAD_i32; /* color - 1 dword */ + int color_idx = FREAD_i32; /* color - 1 dword */ res->line_color.bbggrr = gt_color_value(color_idx); - points = FREAD_i32; + int points = FREAD_i32; for (int index = 0; index < points; index++) { Waypoint* wpt = new Waypoint; @@ -1044,17 +1026,15 @@ gdb_rd_deinit() static void read_data() { - gbfile* fsave; int incomplete = 0; /* number of incomplete reads */ for (;;) { - int len, delta; - char typ, dump; + char typ; gt_waypt_classes_e wpt_class; Waypoint* wpt; route_head* trk, *rte; - len = FREAD_i32; + int len = FREAD_i32; if (FREAD(&typ, 1) < 1) { fatal(MYNAME ": Attempt to read past EOF."); } @@ -1067,19 +1047,18 @@ read_data() gbfcopyfrom(ftmp, fin, len); gbfrewind(ftmp); - fsave = fin; /* swap standard 'fin' with cached input */ + gbfile* fsave = fin; /* swap standard 'fin' with cached input */ fin = ftmp; - dump = 1; + char dump = 1; wpt_class = GDB_DEF_CLASS; switch (typ) { case 'W': wpt = read_waypoint(&wpt_class); if ((gdb_via == 0) || (wpt_class == 0)) { - Waypoint* dupe; waypt_add(wpt); - dupe = new Waypoint(*wpt); + Waypoint* dupe = new Waypoint(*wpt); ENQUEUE_TAIL(&wayptq_in, &dupe->Q); } else { ENQUEUE_TAIL(&wayptq_in_hidden, &wpt->Q); @@ -1103,7 +1082,7 @@ read_data() } fin = fsave; - delta = len - gbftell(ftmp); + int delta = len - gbftell(ftmp); is_fatal(delta > 1000000, "Internal consistency error. Delta too big"); // Avoid finite loop on bogus beta files from '06. @@ -1285,14 +1264,13 @@ write_waypoint( const int icon, const int display) { char zbuf[32], ffbuf[32]; - int wpt_class; waypt_ct++; /* increase informational number of written waypoints */ memset(zbuf, 0, sizeof(zbuf)); memset(ffbuf, 0xFF, sizeof(ffbuf)); - wpt_class = wpt->wpt_flags.fmt_use; /* trick */ + int wpt_class = wpt->wpt_flags.fmt_use; /* trick */ FWRITE_CSTR(shortname); /* uniqe (!!!) shortname */ FWRITE_i32(wpt_class); /* waypoint class */ @@ -1334,8 +1312,6 @@ write_waypoint( /* VERSION DEPENDENT CODE */ if (gdb_ver <= GDB_VER_2) { - QString descr; - FWRITE(zbuf, 3); FWRITE(zbuf, 4); QString ld; @@ -1343,8 +1319,8 @@ write_waypoint( UrlLink l = wpt->GetUrlLink(); ld = l.url_; } - descr = (wpt_class < gt_waypt_class_map_point) ? - ld : wpt->description; + QString descr = (wpt_class < gt_waypt_class_map_point) ? + ld : wpt->description; if ((descr != nullptr) && (wpt_class >= gt_waypt_class_map_point) && \ descr == CSTRc(wpt->shortname)) { descr.clear(); @@ -1445,7 +1421,6 @@ static void write_route(const route_head* rte, const QString& rte_name) { bounds bounds; - int points, index; queue* elem, *tmp; char zbuf[32], ffbuf[32]; @@ -1458,18 +1433,15 @@ write_route(const route_head* rte, const QString& rte_name) route_compute_bounds(rte, &bounds); route_write_bounds(&bounds); - points = ELEMENTS(rte); + int points = ELEMENTS(rte); FWRITE_i32(points); - index = 0; + int index = 0; QUEUE_FOR_EACH((queue*)&rte->waypoint_list, elem, tmp) { Waypoint* wpt = (Waypoint*)elem; Waypoint* next = (Waypoint*)tmp; - Waypoint* test; -// garmin_fs_t* gmsd = nullptr; - int wpt_class; index++; rtept_ct++; /* increase informational number of written route points */ @@ -1481,7 +1453,7 @@ write_route(const route_head* rte, const QString& rte_name) gdb_check_waypt(next); } - test = gdb_find_wayptq(&wayptq_out, wpt, 1); + Waypoint* test = gdb_find_wayptq(&wayptq_out, wpt, 1); if (test != nullptr) { wpt = test; } else { @@ -1493,7 +1465,7 @@ write_route(const route_head* rte, const QString& rte_name) /* extra_data may contain a modified shortname */ FWRITE_CSTR((wpt->extra_data) ? (char*)wpt->extra_data : wpt->shortname); - wpt_class = wpt->wpt_flags.fmt_use; /* trick */ + int wpt_class = wpt->wpt_flags.fmt_use; /* trick */ FWRITE_i32(wpt_class); /* waypoint class */ FWRITE_CSTR(GMSD_GET(cc, "")); /* country */ @@ -1570,7 +1542,6 @@ write_track(const route_head* trk, const QString& trk_name) FWRITE_i32(points); /* total number of waypoints in waypoint list */ QUEUE_FOR_EACH((queue*)&trk->waypoint_list, elem, tmp) { - double d; Waypoint* wpt = (Waypoint*)elem; trkpt_ct++; /* increase informational number of written route points */ @@ -1579,7 +1550,7 @@ write_track(const route_head* trk, const QString& trk_name) FWRITE_LATLON(wpt->longitude); FWRITE_DBL(wpt->altitude, unknown_alt); FWRITE_TIME(wpt->GetCreationTime().toTime_t()); - d = WAYPT_GET(wpt, depth, unknown_alt); + double d = WAYPT_GET(wpt, depth, unknown_alt); FWRITE_DBL(d, unknown_alt); d = WAYPT_GET(wpt, temperature, -99999); FWRITE_DBL(d, -99999); @@ -1642,7 +1613,7 @@ write_waypoint_cb(const Waypoint* refpt) } if (test == nullptr) { - int icon, display, wpt_class; + int display; Waypoint* wpt = new Waypoint(*refpt); gdb_check_waypt(wpt); @@ -1654,13 +1625,13 @@ write_waypoint_cb(const Waypoint* refpt) /* prepare the waypoint */ garmin_fs_t* gmsd = GMSD_FIND(wpt); - wpt_class = GMSD_GET(wpt_class, -1); + int wpt_class = GMSD_GET(wpt_class, -1); if (wpt_class == -1) { wpt_class = (route_flag) ? GDB_DEF_HIDDEN_CLASS : GDB_DEF_CLASS; } wpt->wpt_flags.fmt_use = wpt_class; /* trick, we need this for the route(s) */ - icon = GMSD_GET(icon, -1); + int icon = GMSD_GET(icon, -1); if (icon < 0) { if (wpt->icon_descr.isNull()) { icon = GDB_DEF_ICON; @@ -1719,8 +1690,6 @@ write_waypoint_cb(const Waypoint* refpt) static void write_route_cb(const route_head* rte) { - gbfile* fsave; - if (ELEMENTS(rte) <= 0) { return; } @@ -1734,7 +1703,7 @@ write_route_cb(const route_head* rte) rte_ct++; /* increase informational number of written routes */ - fsave = fout; + gbfile* fsave = fout; fout = ftmp; write_route(rte, name); finalize_item(fsave, 'R'); @@ -1743,8 +1712,6 @@ write_route_cb(const route_head* rte) static void write_track_cb(const route_head* trk) { - gbfile* fsave; - if (ELEMENTS(trk) <= 0) { return; } @@ -1758,7 +1725,7 @@ write_track_cb(const route_head* trk) trk_ct++; /* increase informational number of written tracks */ - fsave = fout; + gbfile* fsave = fout; fout = ftmp; write_track(trk, name); diff --git a/geojson.cc b/geojson.cc index 02d5137f8..8fa1ded07 100644 --- a/geojson.cc +++ b/geojson.cc @@ -119,8 +119,7 @@ geojson_wr_deinit() { object[FEATURES] = *feature_collection; QJsonDocument save(object); - QJsonDocument::JsonFormat style; - style = compact_opt ? QJsonDocument::Compact : QJsonDocument::Indented; + QJsonDocument::JsonFormat style = compact_opt ? QJsonDocument::Compact : QJsonDocument::Indented; gbfputs(save.toJson(style),ofd); gbfclose(ofd); diff --git a/ggv_bin.cc b/ggv_bin.cc index affb122cf..15c111c53 100644 --- a/ggv_bin.cc +++ b/ggv_bin.cc @@ -115,14 +115,10 @@ ggv_bin_read_v2(QDataStream& stream) route_head* ggv_bin_track; Waypoint* wpt; double lon, lat; - quint16 header_len; - quint16 entry_type; - quint16 entry_subtype; quint16 line_points; - quint64 entry_pos; // header length is usually either 0x90 or 0x00 - header_len = ggv_bin_read16(stream, "map name len"); + quint16 header_len = ggv_bin_read16(stream, "map name len"); if (header_len > 0) { ggv_bin_read_bytes(stream, buf, header_len, "map name"); buf.remove(0,4); @@ -137,11 +133,11 @@ ggv_bin_read_v2(QDataStream& stream) if (global_opts.debug_level > 1) qDebug("------------------------------------ 0x%llx", stream.device()->pos()); - entry_pos = stream.device()->pos(); - entry_type = ggv_bin_read16(stream, "entry type"); + quint64 entry_pos = stream.device()->pos(); + quint16 entry_type = ggv_bin_read16(stream, "entry type"); ggv_bin_read16(stream, "entry group"); ggv_bin_read16(stream, "entry zoom"); - entry_subtype = ggv_bin_read16(stream, "entry subtype"); + quint16 entry_subtype = ggv_bin_read16(stream, "entry subtype"); if (entry_subtype != 1) { ggv_bin_read_text32(stream, buf, "text len"); @@ -226,8 +222,7 @@ static void ggv_bin_read_v34_header(QDataStream& stream, quint32& number_labels, quint32 &number_records) { QByteArray buf; - quint16 header_len; - + ggv_bin_read_bytes(stream, buf, 8, "unknown"); number_labels = ggv_bin_read32(stream, "num labels"); number_records = ggv_bin_read32(stream, "num records"); @@ -236,7 +231,7 @@ ggv_bin_read_v34_header(QDataStream& stream, quint32& number_labels, quint32 &nu ggv_bin_read16(stream, "unknown"); // 8 bytes ending with 1E 00, contains len of header block ggv_bin_read16(stream, "unknown"); - header_len = ggv_bin_read16(stream, "header len"); + quint16 header_len = ggv_bin_read16(stream, "header len"); ggv_bin_read16(stream, "unknown"); ggv_bin_read16(stream, "unknown"); if (header_len > 0) { @@ -266,10 +261,7 @@ static QString ggv_bin_read_v34_common(QDataStream& stream) { QByteArray buf; - QString res; - quint16 type1; - quint16 type2; - + ggv_bin_read16(stream, "entry group"); ggv_bin_read16(stream, "entry prop2"); ggv_bin_read16(stream, "entry prop3"); @@ -281,12 +273,12 @@ ggv_bin_read_v34_common(QDataStream& stream) ggv_bin_read16(stream, "entry zoom"); ggv_bin_read16(stream, "entry prop10"); ggv_bin_read_text16(stream, buf, "entry txt"); - res = QString::fromLatin1(buf.constData()).simplified(); - type1 = ggv_bin_read16(stream, "entry type1"); + QString res = QString::fromLatin1(buf.constData()).simplified(); + quint16 type1 = ggv_bin_read16(stream, "entry type1"); if (type1 != 1) { ggv_bin_read_text32(stream, buf, "entry object"); } - type2 = ggv_bin_read16(stream, "entry type2"); + quint16 type2 = ggv_bin_read16(stream, "entry type2"); if (type2 != 1) { ggv_bin_read_text32(stream, buf, "entry object"); } @@ -297,10 +289,8 @@ static void ggv_bin_read_v34_record(QDataStream& stream) { QByteArray buf; - QString label; Waypoint *wpt; route_head* ggv_bin_track; - quint16 entry_type; quint32 bmp_len; quint16 line_points; double lon, lat; @@ -308,8 +298,8 @@ ggv_bin_read_v34_record(QDataStream& stream) if (global_opts.debug_level > 1) qDebug("------------------------------------ 0x%llx", stream.device()->pos()); - entry_type = ggv_bin_read16(stream, "entry type"); - label = ggv_bin_read_v34_common(stream); + quint16 entry_type = ggv_bin_read16(stream, "entry type"); + QString label = ggv_bin_read_v34_common(stream); switch (entry_type) { case 0x02: diff --git a/ggv_log.cc b/ggv_log.cc index 42bcc0039..b2317f776 100644 --- a/ggv_log.cc +++ b/ggv_log.cc @@ -52,9 +52,7 @@ ggv_log_rd_init(const QString& fname) fin = gbfopen(fname, "rb", MYNAME); for (;;) { - int cin; - - cin = gbfgetc(fin); + int cin = gbfgetc(fin); if (cin < 0) { break; } @@ -63,12 +61,11 @@ ggv_log_rd_init(const QString& fname) if (cin == '\0') { double ver = 0; - char* sver; if (strncmp(magic, "DOMGVGPS Logfile V", 18) != 0) { break; } - sver = &magic[18]; + char* sver = &magic[18]; sscanf(sver, "%lf:", &ver); ggv_log_ver = ver * 10; if ((ggv_log_ver == 10) || (ggv_log_ver == 25)) { @@ -92,7 +89,6 @@ ggv_log_rd_deinit() static void ggv_log_read() { - signed char* buf; int bufsz = 0, len; route_head* trk = nullptr; @@ -105,14 +101,10 @@ ggv_log_read() break; } - buf = (signed char*) xmalloc(bufsz); + signed char* buf = (signed char*) xmalloc(bufsz); while ((len = gbfread(buf, 1, bufsz, fin))) { - int deg, min; - double xlat, xlon; - float sec; struct tm tm; - Waypoint* wpt; if (len != bufsz) { break; @@ -125,25 +117,23 @@ ggv_log_read() memset(&tm, 0, sizeof(tm)); - wpt = new Waypoint; + Waypoint* wpt = new Waypoint; - deg = (int16_t) le_read16(&buf[0]); - min = le_read16(&buf[2]); - sec = le_read_float(&buf[4]); - xlat = (double)deg + ((double)min / 60.0) + (sec / 3600.0); + int deg = (int16_t) le_read16(&buf[0]); + int min = le_read16(&buf[2]); + float sec = le_read_float(&buf[4]); + double xlat = (double)deg + ((double)min / 60.0) + (sec / 3600.0); wpt->latitude = xlat; deg = (int16_t) le_read16(&buf[8]); min = le_read16(&buf[10]); sec = le_read_float(&buf[12]); - xlon = (double)deg + ((double)min / 60.0) + (sec / 3600.0); + double xlon = (double)deg + ((double)min / 60.0) + (sec / 3600.0); wpt->longitude = xlon; WAYPT_SET(wpt, course, le_read16(&buf[16 + 0])); int milliseconds = 0; if (ggv_log_ver == 10) { - double secs; - wpt->altitude = le_read16(&buf[16 + 2]); WAYPT_SET(wpt, speed, le_read16(&buf[16 + 4])); tm.tm_year = le_read16(&buf[16 + 8]); @@ -151,7 +141,7 @@ ggv_log_read() tm.tm_mday = le_read16(&buf[16 + 12]); tm.tm_hour = le_read16(&buf[16 + 14]); tm.tm_min = le_read16(&buf[16 + 16]); - secs = le_read_double(&buf[16 + 18]); + double secs = le_read_double(&buf[16 + 18]); tm.tm_sec = (int)secs; milliseconds = lround((secs - tm.tm_sec) * 1000.0); } else { @@ -210,19 +200,17 @@ ggv_log_track_head_cb(const route_head* trk) Waypoint* prev = nullptr; QUEUE_FOR_EACH((queue*)&trk->waypoint_list, elem, tmp) { - double latmin, lonmin, latsec, lonsec; - int latint, lonint; double course = 0, speed = 0; struct tm tm; Waypoint* wpt = (Waypoint*)elem; double secs = 0; - latint = wpt->latitude; - lonint = wpt->longitude; - latmin = 60.0 * (fabs(wpt->latitude) - latint); - lonmin = 60.0 * (fabs(wpt->longitude) - lonint); - latsec = 60.0 * (latmin - floor(latmin)); - lonsec = 60.0 * (lonmin - floor(lonmin)); + int latint = wpt->latitude; + int lonint = wpt->longitude; + double latmin = 60.0 * (fabs(wpt->latitude) - latint); + double lonmin = 60.0 * (fabs(wpt->longitude) - lonint); + double latsec = 60.0 * (latmin - floor(latmin)); + double lonsec = 60.0 * (lonmin - floor(lonmin)); if (wpt->creation_time.isValid()) { time_t t = wpt->GetCreationTime().toTime_t(); diff --git a/ggv_ovl.cc b/ggv_ovl.cc index c4fe706b0..a1d108012 100644 --- a/ggv_ovl.cc +++ b/ggv_ovl.cc @@ -100,19 +100,15 @@ ggv_ovl_rd_deinit() static void ggv_ovl_read() { - int symbols; - - symbols = inifile_readint_def(inifile, "Overlay", "Symbols", -1); + int symbols = inifile_readint_def(inifile, "Overlay", "Symbols", -1); for (int i = 1; i <= symbols; i++) { - int points; - OVL_SYMBOL_TYP type; char symbol[32]; snprintf(symbol, sizeof(symbol), "Symbol %d", i); - type = (OVL_SYMBOL_TYP) inifile_readint_def(inifile, symbol, "Typ", 0); - points = inifile_readint_def(inifile, symbol, "Punkte", -1); + OVL_SYMBOL_TYP type = (OVL_SYMBOL_TYP) inifile_readint_def(inifile, symbol, "Typ", 0); + int points = inifile_readint_def(inifile, symbol, "Punkte", -1); switch (type) { @@ -129,9 +125,9 @@ ggv_ovl_read() } if (points > 0) { - route_head* rte, *trk; + route_head* trk; - rte = trk = route_head_alloc(); + route_head* rte = trk = route_head_alloc(); if (group > 1) { route_add_head(rte); route_ct++; @@ -270,7 +266,6 @@ waypt_disp_cb(const Waypoint* wpt) static void track_disp_cb(const route_head* trk) { - int i; queue* elem, *tmp; int waypt_ct = trk->rte_waypt_ct; @@ -284,7 +279,7 @@ track_disp_cb(const route_head* trk) gbfprintf(fout, "Size=105\n"); gbfprintf(fout, "Punkte=%d\n", waypt_ct); - i = 0; + int i = 0; QUEUE_FOR_EACH(&(trk->waypoint_list), elem, tmp) { @@ -302,9 +297,7 @@ track_disp_cb(const route_head* trk) static void route_disp_cb(const route_head* rte) { - int i; queue* elem, *tmp; - Waypoint* prev; int waypt_ct = rte->rte_waypt_ct; if (waypt_ct <= 0) { @@ -315,8 +308,8 @@ route_disp_cb(const route_head* rte) color = OVL_COLOR_RED; - i = 0; - prev = nullptr; + int i = 0; + Waypoint* prev = nullptr; QUEUE_FOR_EACH(&(rte->waypoint_list), elem, tmp) { @@ -391,21 +384,17 @@ draw_symbol_basics(const OVL_SYMBOL_TYP typ, const int art, const OVL_COLOR_TYP static int get_direction(const Waypoint* A, const Waypoint* B) { - double lata, lona, latb, lonb; - double dist, dir; - int res; - - lata = RAD(A->latitude); - lona = RAD(A->longitude); - latb = RAD(B->latitude); - lonb = RAD(B->longitude); + double lata = RAD(A->latitude); + double lona = RAD(A->longitude); + double latb = RAD(B->latitude); + double lonb = RAD(B->longitude); - dist = gcdist(lata, lona, latb, lonb); - dir = acos((sin(latb) - sin(lata) * cos(dist)) / (cos(lata) * sin(dist))); + double dist = gcdist(lata, lona, latb, lonb); + double dir = acos((sin(latb) - sin(lata) * cos(dist)) / (cos(lata) * sin(dist))); if (lonb < lona) { dir = -dir; } - res = (int) DEG(dir); + int res = (int) DEG(dir); res = 360 - (res + 270); if (res < 0) { res += 360; diff --git a/globalsat_sport.cc b/globalsat_sport.cc index 7b7bdcce0..bcda37a91 100644 --- a/globalsat_sport.cc +++ b/globalsat_sport.cc @@ -223,9 +223,8 @@ serial_deinit() static int serial_recv_byte() { - int result; /* allow for a delay of 4s */ - result = gbser_readc_wait(serial_handle, 4000); + int result = gbser_readc_wait(serial_handle, 4000); switch (result) { case gbser_ERROR: fatal("serial_recv_byte(): error reading one byte\n"); @@ -240,12 +239,11 @@ serial_recv_byte() static void serial_write_byte(uint8_t byte) { - int n; if (global_opts.debug_level > 1) { printf("0x%02x (%d), ", byte, byte); } - n = gbser_writec(serial_handle, byte); + int n = gbser_writec(serial_handle, byte); if (n == gbser_ERROR) { fatal("globalsat_probe_device(): write failed\n"); } @@ -259,8 +257,7 @@ recv_byte() if (!opt_input_dump_file) { result=serial_recv_byte(); } else { - int bytes; - bytes=gbfread(&result, 1, 1, in_file); + int bytes = gbfread(&result, 1, 1, in_file); is_fatal((bytes != 1), MYNAME ": read error"); } // Check if byte sould be dumped also into a file @@ -322,26 +319,24 @@ globalsat_write_package(uint8_t* payload, uint32_t size) static uint8_t* globalsat_read_package(int* out_length, uint8_t* out_DeviceCommand) { - uint8_t DeviceCommand, len_h, len_l, crc; - uint8_t* payload; - int length; + uint8_t crc; uint8_t calc_crc = 0; - DeviceCommand = recv_byte(); + uint8_t DeviceCommand = recv_byte(); if (global_opts.debug_level > 1) { printf("DeviceCommand: 0x%02x ", DeviceCommand); } - len_h = recv_byte(); + uint8_t len_h = recv_byte(); calc_crc ^= len_h; - len_l = recv_byte(); + uint8_t len_l = recv_byte(); calc_crc ^= len_l; - length = (len_h << 8) + len_l; + int length = (len_h << 8) + len_l; if (global_opts.debug_level > 1) { printf("len=%d Payload:", length); } - payload = (uint8_t*) malloc(length); + uint8_t* payload = (uint8_t*) malloc(length); if (payload == nullptr) { goto error_out; } @@ -386,10 +381,9 @@ globalsat_probe_device() globalsat_send_simple(CommandWhoAmI); - uint8_t* payload; int len; uint8_t DeviceCommand; - payload = globalsat_read_package(&len, &DeviceCommand); + uint8_t* payload = globalsat_read_package(&len, &DeviceCommand); if ((len > 0) && (payload != nullptr)) { if (global_opts.debug_level > 1) { printf("Got package!!!\n"); @@ -482,10 +476,9 @@ waypoint_read() //CommandGetTrackFileHeaders globalsat_send_simple(CommandGetWaypoints); - uint8_t* in_payload; int len; uint8_t DeviceCommand; - in_payload = globalsat_read_package(&len, &DeviceCommand); + uint8_t* in_payload = globalsat_read_package(&len, &DeviceCommand); if ((len > 0) && (in_payload != nullptr)) { if (global_opts.debug_level > 1) { printf("Got package!!!\n"); @@ -509,17 +502,15 @@ track_read() printf("Sent...\n"); } - uint8_t* payload; int length; uint8_t DeviceCommand; - payload = globalsat_read_package(&length, &DeviceCommand); + uint8_t* payload = globalsat_read_package(&length, &DeviceCommand); if ((length > 0) && (payload != nullptr)) { if (global_opts.debug_level > 1) { printf("Got package!!! headers\n"); } - int number_headers; //payload is packed with a number of trainingheaders with the size of 29bytes each - number_headers = length / 29; //29=packed sizeof(gh_trainheader) + int number_headers = length / 29; //29=packed sizeof(gh_trainheader) if (global_opts.debug_level > 1) { printf("length=%d sizeof(gh_trainheader)=%d number_headers=%d\n", length, 29, number_headers); } diff --git a/gnav_trl.cc b/gnav_trl.cc index beb19d1fe..8d7d172e0 100644 --- a/gnav_trl.cc +++ b/gnav_trl.cc @@ -91,13 +91,12 @@ gnav_trl_read() while (! gbfeof(fin)) { gnav_trl_t rec; - Waypoint* wpt; if (gbfread(&rec, sizeof(rec), 1, fin) != 1) { fatal(MYNAME ": Unexpected EOF (end of file)!\n"); } - wpt = new Waypoint; + Waypoint* wpt = new Waypoint; wpt->SetCreationTime(le_read32(&rec.time)); wpt->latitude = le_read_float(&rec.lat); diff --git a/gopal.cc b/gopal.cc index cb2bc0564..3537b8a39 100644 --- a/gopal.cc +++ b/gopal.cc @@ -103,7 +103,6 @@ static int gopal_check_line(char* line) static void gopal_rd_init(const QString& fname) { - char* ck; CHECK_BOOL(optclean); if (optminspeed) { minspeed=atof(optminspeed); @@ -130,7 +129,7 @@ gopal_rd_init(const QString& fname) if (optdate) { memset(&opt_tm, 0, sizeof(opt_tm)); - ck = strptime(optdate, "%Y%m%d", &opt_tm); + char* ck = strptime(optdate, "%Y%m%d", &opt_tm); if ((ck == nullptr) || (*ck != '\0') || (strlen(optdate) != 8)) { fatal(MYNAME ": Invalid date \"%s\"!\n", optdate); } else if (opt_tm.tm_year < 70) { @@ -169,20 +168,16 @@ gopal_read() { char* buff; - char* str, *c; - int column; - long line; - double hmsd,speed; - int fix, hms; - route_head* route; - Waypoint* wpt, *lastwpt=nullptr; - double lat_old; + double hmsd; + int fix; + int hms; + Waypoint* lastwpt=nullptr; char tbuffer[64]; struct tm tm2; - lat_old=0; + double lat_old = 0; - route = route_head_alloc(); + route_head* route = route_head_alloc(); QDateTime qtx; qtx.setTimeSpec(Qt::UTC); qtx.setTime_t(tx); @@ -190,18 +185,17 @@ gopal_read() route->rte_name += qtx.toString(Qt::ISODate); route_add_head(route); - line=0; + long line = 0; while ((buff = gbfgetstr(fin))) { - int nfields; if ((line == 0) && fin->unicode) { cet_convert_init(CET_CHARSET_UTF8, 1); } - str = buff = lrtrim(buff); + char* str = buff = lrtrim(buff); if (*buff == '\0') { continue; } - nfields = gopal_check_line(buff); + int nfields = gopal_check_line(buff); if ((nfields != 8) && (nfields != 11)) { continue; } @@ -209,13 +203,13 @@ gopal_read() if ((nfields == 8) && (tx == 0)) { // fatal(MYNAME ": Invalid date in filename \"%s\", try to set manually using \"date\" switch!\n", buff); } - wpt = new Waypoint; + Waypoint* wpt = new Waypoint; - column = -1; + int column = -1; // the format of gopal is quite simple. Unfortunately the developers forgot the date as the first element... //TICK; TIME; LONG; LAT; HEIGHT; SPEED; Fix; HDOP; SAT //3801444, 080558, 2.944362, 43.262117, 295.28, 0.12964, 2, 2.900000, 3 - c = csv_lineparse(str, ",", "", column++); + char* c = csv_lineparse(str, ",", "", column++); int millisecs = 0; while (c != nullptr) { switch (column) { @@ -313,7 +307,7 @@ gopal_read() lastwpt=wpt; } //calculate the speed to reach this waypoint from the last. This way I try to sort out invalid waypoints - speed=0; + double speed = 0; if (lastwpt !=nullptr) { speed=3.6*radtometers(gcdist(RAD(lastwpt->latitude), RAD(lastwpt->longitude), RAD(wpt->latitude), RAD(wpt->longitude))) / abs((int)(wpt->creation_time.toTime_t() - lastwpt->GetCreationTime().toTime_t())); @@ -354,7 +348,6 @@ static void gopal_write_waypt(const Waypoint* wpt) { char tbuffer[64]; - unsigned long timestamp; int fix=fix_unknown; //TICK; TIME; LONG; LAT; HEIGHT; SPEED; UN; HDOP; SAT //3801444, 080558, 2.944362, 43.262117, 295.28, 0.12964, 2, 2.900000, 3 @@ -373,7 +366,7 @@ gopal_write_waypt(const Waypoint* wpt) } } //MSVC handles time_t as int64, gcc and mac only int32, so convert it: - timestamp=(unsigned long)wpt->GetCreationTime().toTime_t(); + unsigned long timestamp = (unsigned long)wpt->GetCreationTime().toTime_t(); gbfprintf(fout, "%lu, %s, %lf, %lf, %5.1lf, %8.5lf, %d, %lf, %d\n",timestamp,tbuffer, wpt->longitude, wpt->latitude,wpt->altitude, wpt->speed,fix,wpt->hdop,wpt->sat); } diff --git a/gpssim.cc b/gpssim.cc index 2f5e89a53..277f87c44 100644 --- a/gpssim.cc +++ b/gpssim.cc @@ -108,14 +108,13 @@ static void gpssim_write_pt(const Waypoint* wpt) { char obuf[1024]; - double lat, lon; if WAYPT_HAS(wpt, speed) { gpssim_write_spd(MPS_TO_KNOTS(wpt->speed)); } - lat = degrees2ddmm(wpt->latitude); - lon = degrees2ddmm(wpt->longitude); + double lat = degrees2ddmm(wpt->latitude); + double lon = degrees2ddmm(wpt->longitude); snprintf(obuf, sizeof(obuf), "FRWPT,%10.5f,%c,%011.5f,%c,%.1f", fabs(lat), lat < 0 ? 'S' : 'N', @@ -125,13 +124,11 @@ gpssim_write_pt(const Waypoint* wpt) if (wpt->creation_time.isValid()) { char tbuf[20]; - int hms, ymd; - struct tm* tm; const time_t tt = wpt->GetCreationTime().toTime_t(); - tm = gmtime(&tt); - hms = tm->tm_hour * 10000 + tm->tm_min * 100 + tm->tm_sec; - ymd = tm->tm_mday * 10000 + tm->tm_mon * 100 + tm->tm_year; + struct tm* tm = gmtime(&tt); + int hms = tm->tm_hour * 10000 + tm->tm_min * 100 + tm->tm_sec; + int ymd = tm->tm_mday * 10000 + tm->tm_mon * 100 + tm->tm_year; snprintf(tbuf, sizeof(tbuf), ",%d,%d",ymd, hms); strcat(obuf, tbuf); diff --git a/gpsutil.cc b/gpsutil.cc index f3a930f06..3dce470fe 100644 --- a/gpsutil.cc +++ b/gpsutil.cc @@ -65,11 +65,9 @@ data_read() char desc[31]; double lat,lon; char latdir, londir; - int ilat, ilon; long alt; char alttype; char icon[3]; - Waypoint* wpt_tmp; int line = 0; /* * Make sure that all waypoints in single read have same @@ -79,7 +77,6 @@ data_read() icon[0] = 0; while ((ibuf = gbfgetstr(file_in))) { - int n, len; char* sn; if ((line++ == 0) && file_in->unicode) { @@ -88,7 +85,7 @@ data_read() /* A sharp in column zero or an blank line is a comment */ ibuf = lrtrim(ibuf); - len = strlen(ibuf); + int len = strlen(ibuf); if ((len == 0) || (*ibuf == '#')) { continue; } @@ -102,9 +99,9 @@ data_read() ibuf += 9; } - n = sscanf(ibuf, "%lf%c %lf%c %ld%c %30[^,] %2s", - &lat, &latdir, &lon, &londir, - &alt, &alttype, desc, icon); + int n = sscanf(ibuf, "%lf%c %lf%c %ld%c %30[^,] %2s", + &lat, &latdir, &lon, &londir, + &alt, &alttype, desc, icon); /* Require at least first threee fields, otherwise ignore */ if (n < 2) { xfree(sn); @@ -113,7 +110,7 @@ data_read() rtrim(sn); rtrim(desc); rtrim(icon); - wpt_tmp = new Waypoint; + Waypoint* wpt_tmp = new Waypoint; wpt_tmp->altitude = alt; wpt_tmp->shortname = sn; xfree(sn); @@ -129,9 +126,9 @@ data_read() lat /= 100.0; lon /= 100.0; - ilon = (int)(lon); + int ilon = (int)(lon); wpt_tmp->longitude = ilon + (lon - ilon)*(100.0/60.0); - ilat = (int)(lat); + int ilat = (int)(lat); wpt_tmp->latitude = ilat + (lat - ilat) * (100.0/60.0); wpt_tmp->icon_descr = mag_find_descr_from_token(icon); waypt_add(wpt_tmp); @@ -141,14 +138,12 @@ data_read() static void gpsutil_disp(const Waypoint* wpt) { - double lon,lat; - QString icon_token; char* tdesc = xstrdup(wpt->description); - icon_token = mag_find_token_from_descr(wpt->icon_descr); + QString icon_token = mag_find_token_from_descr(wpt->icon_descr); - lon = degrees2ddmm(wpt->longitude); - lat = degrees2ddmm(wpt->latitude); + double lon = degrees2ddmm(wpt->longitude); + double lat = degrees2ddmm(wpt->latitude); gbfprintf(file_out, "%-8.8s %08.3f%c %09.3f%c %07.0f%c %-30.30s %s\n", global_opts.synthesize_shortnames ? diff --git a/gpx.cc b/gpx.cc index 4f90f7104..eb4d84f39 100644 --- a/gpx.cc +++ b/gpx.cc @@ -267,14 +267,13 @@ static void gpx_write_gdata(gpx_global_entry* ge, const char* tag) { queue* elem, *tmp; - gpx_global_entry* gep; if (!gpx_global || QUEUE_EMPTY(&ge->queue)) { return; } writer->writeStartElement(tag); QUEUE_FOR_EACH(&ge->queue, elem, tmp) { - gep = BASE_STRUCT(elem, gpx_global_entry, queue); + gpx_global_entry* gep = BASE_STRUCT(elem, gpx_global_entry, queue); writer->writeCharacters(gep->tagdata); /* Some tags we just output once. */ if ((0 == strcmp(tag, "url")) || @@ -528,23 +527,18 @@ tag_gs_cache(const QXmlStreamAttributes& attr) static void start_something_else(const QString& el, const QXmlStreamAttributes& attr) { - char** avcp; - int attr_count; - xml_tag* new_tag; - fs_xml* fs_gpx; - if (!fs_ptr) { return; } - new_tag = new xml_tag; + xml_tag* new_tag = new xml_tag; new_tag->tagname = el; - attr_count = attr.size(); + int attr_count = attr.size(); const QXmlStreamNamespaceDeclarations nsdecl = reader->namespaceDeclarations(); const int ns_count = nsdecl.size(); new_tag->attributes = (char**)xcalloc(sizeof(char*),2*(attr_count+ns_count)+1); - avcp = new_tag->attributes; + char** avcp = new_tag->attributes; for (int i = 0; i < attr_count; i++) { *avcp = xstrdup(attr[i].qualifiedName().toString()); avcp++; @@ -573,7 +567,7 @@ start_something_else(const QString& el, const QXmlStreamAttributes& attr) new_tag->parent = cur_tag; } } else { - fs_gpx = (fs_xml*)fs_chain_find(*fs_ptr, FS_GPX); + fs_xml* fs_gpx = (fs_xml*)fs_chain_find(*fs_ptr, FS_GPX); if (fs_gpx && fs_gpx->tag) { cur_tag = fs_gpx->tag; @@ -639,14 +633,13 @@ static void gpx_start(const QString& el, const QXmlStreamAttributes& attr) { int passthrough; - int tag; /* * Reset end-of-string without actually emptying/reallocing cdatastr. */ cdatastr = QString(); - tag = get_tag(current_tag, &passthrough); + int tag = get_tag(current_tag, &passthrough); switch (tag) { case tt_gpx: tag_gpx(attr); @@ -874,12 +867,11 @@ gpx_end(const QString&) float x; int passthrough; static QDateTime gc_log_date; - tag_type tag; // Remove leading, trailing whitespace. cdatastr = cdatastr.trimmed(); - tag = get_tag(current_tag, &passthrough); + tag_type tag = get_tag(current_tag, &passthrough); switch (tag) { /* @@ -1163,7 +1155,6 @@ static void gpx_cdata(const QString& s) { QString* cdata; - xml_tag* tmp_tag; cdatastr += s; if (!cur_tag) { @@ -1171,7 +1162,7 @@ gpx_cdata(const QString& s) } if (cur_tag->child) { - tmp_tag = cur_tag->child; + xml_tag* tmp_tag = cur_tag->child; while (tmp_tag->sibling) { tmp_tag = tmp_tag->sibling; } @@ -1406,8 +1397,7 @@ gpx_read() static void write_tag_attributes(xml_tag* tag) { - char** pa; - pa = tag->attributes; + char** pa = tag->attributes; if (pa) { while (*pa) { writer->writeAttribute(pa[0], pa[1]); @@ -1453,14 +1443,12 @@ fprint_xml_chain(xml_tag* tag, const Waypoint* wpt) void free_gpx_extras(xml_tag* tag) { - char** ap; - while (tag) { if (tag->child) { free_gpx_extras(tag->child); } if (tag->attributes) { - ap = tag->attributes; + char** ap = tag->attributes; while (*ap) { xfree(*ap++); @@ -1663,24 +1651,20 @@ gpx_write_common_description(const Waypoint* waypointp, const QString& oname) static void gpx_waypt_pr(const Waypoint* waypointp) { - QString oname; - fs_xml* fs_gpx; - garmin_fs_t* gmsd; /* gARmIN sPECIAL dATA */ - writer->writeStartElement(QStringLiteral("wpt")); writer->writeAttribute(QStringLiteral("lat"), toString(waypointp->latitude)); writer->writeAttribute(QStringLiteral("lon"), toString(waypointp->longitude)); - oname = global_opts.synthesize_shortnames ? - mkshort_from_wpt(mkshort_handle, waypointp) : - waypointp->shortname; + QString oname = global_opts.synthesize_shortnames ? + mkshort_from_wpt(mkshort_handle, waypointp) : + waypointp->shortname; gpx_write_common_position(waypointp, gpxpt_waypoint); gpx_write_common_description(waypointp, oname); gpx_write_common_acc(waypointp); if (!(opt_humminbirdext || opt_garminext)) { - fs_gpx = (fs_xml*)fs_chain_find(waypointp->fs, FS_GPX); - gmsd = GMSD_FIND(waypointp); + fs_xml* fs_gpx = (fs_xml*)fs_chain_find(waypointp->fs, FS_GPX); + garmin_fs_t* gmsd = GMSD_FIND(waypointp); /* gARmIN sPECIAL dATA */ if (fs_gpx) { if (! gmsd) { fprint_xml_chain(fs_gpx->tag, waypointp); @@ -1699,7 +1683,6 @@ gpx_waypt_pr(const Waypoint* waypointp) static void gpx_track_hdr(const route_head* rte) { - fs_xml* fs_gpx; current_trk_head = rte; writer->writeStartElement(QStringLiteral("trk")); @@ -1712,7 +1695,7 @@ gpx_track_hdr(const route_head* rte) if (gpx_wversion_num > 10) { if (!(opt_humminbirdext || opt_garminext)) { - fs_gpx = (fs_xml*)fs_chain_find(rte->fs, FS_GPX); + fs_xml* fs_gpx = (fs_xml*)fs_chain_find(rte->fs, FS_GPX); if (fs_gpx) { fprint_xml_chain(fs_gpx->tag, nullptr); } @@ -1735,7 +1718,6 @@ gpx_track_hdr(const route_head* rte) static void gpx_track_disp(const Waypoint* waypointp) { - fs_xml* fs_gpx; bool first_in_trk = waypointp->Q.prev == ¤t_trk_head->waypoint_list; if (waypointp->wpt_flags.new_trkseg) { @@ -1751,20 +1733,16 @@ gpx_track_disp(const Waypoint* waypointp) gpx_write_common_position(waypointp, gpxpt_track); - /* GPX doesn't require a name on output, so if we made one up - * on input, we might as well say nothing. - */ - QString oname; - oname = global_opts.synthesize_shortnames ? - mkshort_from_wpt(mkshort_handle, waypointp) : - waypointp->shortname; + QString oname = global_opts.synthesize_shortnames ? + mkshort_from_wpt(mkshort_handle, waypointp) : + waypointp->shortname; gpx_write_common_description(waypointp, waypointp->wpt_flags.shortname_is_synthetic ? nullptr : oname); gpx_write_common_acc(waypointp); if (!(opt_humminbirdext || opt_garminext)) { - fs_gpx = (fs_xml*)fs_chain_find(waypointp->fs, FS_GPX); + fs_xml* fs_gpx = (fs_xml*)fs_chain_find(waypointp->fs, FS_GPX); if (fs_gpx) { fprint_xml_chain(fs_gpx->tag, waypointp); } @@ -1795,8 +1773,6 @@ void gpx_track_pr() static void gpx_route_hdr(const route_head* rte) { - fs_xml* fs_gpx; - writer->writeStartElement(QStringLiteral("rte")); writer->writeOptionalTextElement(QStringLiteral("name"), rte->rte_name); writer->writeOptionalTextElement(QStringLiteral("desc"), rte->rte_desc); @@ -1807,7 +1783,7 @@ gpx_route_hdr(const route_head* rte) if (gpx_wversion_num > 10) { if (!(opt_humminbirdext || opt_garminext)) { - fs_gpx = (fs_xml*)fs_chain_find(rte->fs, FS_GPX); + fs_xml* fs_gpx = (fs_xml*)fs_chain_find(rte->fs, FS_GPX); if (fs_gpx) { fprint_xml_chain(fs_gpx->tag, nullptr); } @@ -1832,21 +1808,19 @@ gpx_route_hdr(const route_head* rte) static void gpx_route_disp(const Waypoint* waypointp) { - QString oname; - fs_xml* fs_gpx; writer->writeStartElement(QStringLiteral("rtept")); writer->writeAttribute(QStringLiteral("lat"), toString(waypointp->latitude)); writer->writeAttribute(QStringLiteral("lon"), toString(waypointp->longitude)); - oname = global_opts.synthesize_shortnames ? - mkshort_from_wpt(mkshort_handle, waypointp) : - waypointp->shortname; + QString oname = global_opts.synthesize_shortnames ? + mkshort_from_wpt(mkshort_handle, waypointp) : + waypointp->shortname; gpx_write_common_position(waypointp, gpxpt_route); gpx_write_common_description(waypointp, oname); gpx_write_common_acc(waypointp); if (!(opt_humminbirdext || opt_garminext)) { - fs_gpx = (fs_xml*)fs_chain_find(waypointp->fs, FS_GPX); + fs_xml* fs_gpx = (fs_xml*)fs_chain_find(waypointp->fs, FS_GPX); if (fs_gpx) { fprint_xml_chain(fs_gpx->tag, waypointp); } diff --git a/grtcirc.cc b/grtcirc.cc index 4bd2c47f0..f3f8fcc8c 100644 --- a/grtcirc.cc +++ b/grtcirc.cc @@ -68,15 +68,12 @@ double radtometers(double rads) double gcdist(double lat1, double lon1, double lat2, double lon2) { - double res; - double sdlat, sdlon; - errno = 0; - sdlat = sin((lat1 - lat2) / 2.0); - sdlon = sin((lon1 - lon2) / 2.0); + double sdlat = sin((lat1 - lat2) / 2.0); + double sdlon = sin((lon1 - lon2) / 2.0); - res = sqrt(sdlat * sdlat + cos(lat1) * cos(lat2) * sdlon * sdlon); + double res = sqrt(sdlat * sdlat + cos(lat1) * cos(lat2) * sdlon * sdlon); if (res > 1.0) { res = 1.0; @@ -99,9 +96,8 @@ double gcdist(double lat1, double lon1, double lat2, double lon2) */ double heading(double lat1, double lon1, double lat2, double lon2) { - double v1, v2; - v1 = sin(lon1 - lon2) * cos(lat2); - v2 = cos(lat1) * sin(lat2) - sin(lat1) * cos(lat2) * cos(lon1 - lon2); + double v1 = sin(lon1 - lon2) * cos(lat2); + double v2 = cos(lat1) * sin(lat2) - sin(lat1) * cos(lat2) * cos(lon1 - lon2); /* rounding error protection */ if (fabs(v1) < 1e-15) { v1 = 0.0; @@ -143,8 +139,6 @@ double linedistprj(double lat1, double lon1, double dot; - int newpoints; - *prjlat = lat1; *prjlon = lon1; *frac = 0; @@ -157,7 +151,7 @@ double linedistprj(double lat1, double lon1, lat3 = RAD(lat3); lon3 = RAD(lon3); - newpoints = 1; + int newpoints = 1; if (lat1 == _lat1 && lat2 == _lat2 && lon1 == _lon1 && lon2 == _lon2) { newpoints = 0; } else { @@ -304,9 +298,7 @@ void linepart(double lat1, double lon1, double frac, double* reslat, double* reslon) { - double x1, y1, z1; - double x2, y2, z2; - double xa, ya, za, la; + double xa, ya, za; /* result must be in degrees */ *reslat = lat1; @@ -319,18 +311,18 @@ void linepart(double lat1, double lon1, lon2 = RAD(lon2); /* polar to ECEF rectangular */ - x1 = cos(lon1) * cos(lat1); - y1 = sin(lat1); - z1 = sin(lon1) * cos(lat1); - x2 = cos(lon2) * cos(lat2); - y2 = sin(lat2); - z2 = sin(lon2) * cos(lat2); + double x1 = cos(lon1) * cos(lat1); + double y1 = sin(lat1); + double z1 = sin(lon1) * cos(lat1); + double x2 = cos(lon2) * cos(lat2); + double y2 = sin(lat2); + double z2 = sin(lon2) * cos(lat2); /* 'a' is the axis; the line that passes through the center of the earth * and is perpendicular to the great circle through point 1 and point 2 * It is computed by taking the cross product of the '1' and '2' vectors.*/ crossproduct(x1, y1, z1, x2, y2, z2, &xa, &ya, &za); - la = sqrt(xa * xa + ya * ya + za * za); + double la = sqrt(xa * xa + ya * ya + za * za); if (la) { xa /= la; diff --git a/gtm.cc b/gtm.cc index 985183ab8..3da5e69df 100644 --- a/gtm.cc +++ b/gtm.cc @@ -75,14 +75,13 @@ fread_bool(gbfile* fd) static QString fread_string(gbfile* fd) { - char* val; int len = fread_integer(fd); if (len == 0) { return nullptr; } - val = (char*) xmalloc(len+1); + char* val = (char*) xmalloc(len+1); gbfread(val, 1, len, fd); while (len != 0 && val[len-1] == ' ') { len--; @@ -394,9 +393,8 @@ static void convert_datum(double* lat, double* lon) static void gtm_rd_init(const QString& fname) { - int version; file_in = gbfopen_le(fname, "rb", MYNAME); - version = fread_integer(file_in); + int version = fread_integer(file_in); QString name = fread_fixedstring(file_in, 10); if (version == -29921) { fatal(MYNAME ": Uncompress the file first\n"); diff --git a/height.cc b/height.cc index e691a5612..d5c9ddf01 100644 --- a/height.cc +++ b/height.cc @@ -34,8 +34,6 @@ double HeightFilter::bilinear(double x1, double y1, double x2, double y2, double x, double y, double z11, double z12, double z21, double z22) { - double delta; - if (y1 == y2 && x1 == x2) { return (z11); } @@ -46,7 +44,7 @@ double HeightFilter::bilinear(double x1, double y1, double x2, double y2, double return (z22*(y-y1)+z11*(y2-y))/(y2-y1); } - delta=(y2-y1)*(x2-x1); + double delta = (y2-y1)*(x2-x1); return (z22*(y-y1)*(x-x1)+z12*(y2-y)*(x-x1)+z21*(y-y1)*(x2-x)+z11*(y2-y)*(x2-x))/delta; } @@ -55,8 +53,7 @@ double HeightFilter::bilinear(double x1, double y1, double x2, double y2, double double HeightFilter::wgs84_separation(double lat, double lon) { #include "heightgrid.h" - int ilat, ilon; - int ilat1, ilat2, ilon1, ilon2; + /* sanity checks to prevent segfault on bad data */ if ((lat > 90.0) || (lat < -90.0)) { @@ -66,13 +63,13 @@ double HeightFilter::wgs84_separation(double lat, double lon) fatal(MYNAME ": Invalid longitude value (%f)\n", lon); } - ilat=(int)floor((90.0+lat)/GEOID_GRID_DEG); - ilon=(int)floor((180.0+lon)/GEOID_GRID_DEG); + int ilat = (int)floor((90.0+lat)/GEOID_GRID_DEG); + int ilon = (int)floor((180.0+lon)/GEOID_GRID_DEG); - ilat1=ilat; - ilon1=ilon; - ilat2=(ilat < GEOID_ROW-1)? ilat+1:ilat; - ilon2=(ilon < GEOID_COL-1)? ilon+1:ilon; + int ilat1 = ilat; + int ilon1 = ilon; + int ilat2 = (ilat < GEOID_ROW-1)? ilat+1:ilat; + int ilon2 = (ilon < GEOID_COL-1)? ilon+1:ilon; return bilinear( ilon1*GEOID_GRID_DEG-180.0,ilat1*GEOID_GRID_DEG-90.0, diff --git a/hiketech.cc b/hiketech.cc index 586952720..726f7c945 100644 --- a/hiketech.cc +++ b/hiketech.cc @@ -268,7 +268,6 @@ static void ht_trk_utc(xg_string args, const QXmlStreamAttributes*) { struct tm tm; - time_t utc; sscanf(CSTRc(args), "%d-%d-%d %d:%d:%d", &tm.tm_year, &tm.tm_mon, @@ -278,7 +277,7 @@ void ht_trk_utc(xg_string args, const QXmlStreamAttributes*) tm.tm_year -= 1900; tm.tm_isdst = 0; - utc = mkgmtime(&tm); + time_t utc = mkgmtime(&tm); wpt_tmp->SetCreationTime(utc); } diff --git a/holux.cc b/holux.cc index ae5e9a792..ea6696f2c 100644 --- a/holux.cc +++ b/holux.cc @@ -77,33 +77,30 @@ static void wr_deinit() static void data_read() { - char name[9], desc[90]; - unsigned char* HxWpt; - int iDataRead; - int iWptNum; - WPT* pWptHxTmp; + char name[9]; + char desc[90]; struct tm tm; struct tm* ptm; memset(&tm, 0, sizeof(tm)); - HxWpt = (unsigned char*) xcalloc(GM100_WPO_FILE_SIZE, 1); + unsigned char* HxWpt = (unsigned char*) xcalloc(GM100_WPO_FILE_SIZE, 1); /* read the wpo file to the data-array */ - iDataRead = gbfread(HxWpt, 1, GM100_WPO_FILE_SIZE, file_in); + int iDataRead = gbfread(HxWpt, 1, GM100_WPO_FILE_SIZE, file_in); if (iDataRead == 0) { fatal(MYNAME ": Error reading data from %s.\n", file_in->name); } - iWptNum = le_read16(&((WPTHDR*)HxWpt)->num); + int iWptNum = le_read16(&((WPTHDR*)HxWpt)->num); /* Get the waypoints */ for (int iCount = 0; iCount < iWptNum ; iCount ++) { Waypoint* wpt_tmp = new Waypoint; int iWptIndex = le_read16(&((WPTHDR*)HxWpt)->idx[iCount]); - pWptHxTmp = (WPT*)&HxWpt[OFFS_WPT + (sizeof(WPT) * iWptIndex)]; + WPT* pWptHxTmp = (WPT*)&HxWpt[OFFS_WPT + (sizeof(WPT) * iWptIndex)]; wpt_tmp->altitude = 0; strncpy(name,pWptHxTmp->name,sizeof(pWptHxTmp->name)); @@ -181,9 +178,6 @@ static const char* mknshort(const char* stIn,unsigned int sLen) static void holux_disp(const Waypoint* wpt) { - short sIndex; - WPT* pWptHxTmp; - double lon = wpt->longitude * 36000.0; double lat = wpt->latitude * -36000.0; @@ -196,14 +190,14 @@ static void holux_disp(const Waypoint* wpt) lat += (double)((int)lat/abs((int)lat)) * .5; } - sIndex = le_read16(&((WPTHDR*)HxWFile)->num); + short sIndex = le_read16(&((WPTHDR*)HxWFile)->num); ((WPTHDR*)HxWFile)->idx[sIndex] = sIndex; /* set the waypoint index */ le_write16(&((WPTHDR*)HxWFile)->idx[sIndex], sIndex); /* set the waypoint index */ ((WPTHDR*)HxWFile)->used[sIndex] = 0xff; /* Waypoint used */ /* set Waypoint */ - pWptHxTmp = (WPT*)&HxWFile[OFFS_WPT + (sizeof(WPT) * sIndex)]; + WPT* pWptHxTmp = (WPT*)&HxWFile[OFFS_WPT + (sizeof(WPT) * sIndex)]; memset(pWptHxTmp->name,0x20,sizeof(pWptHxTmp->name)); if (wpt->shortname != nullptr) { @@ -253,7 +247,6 @@ static void holux_disp(const Waypoint* wpt) static void data_write() { - int iWritten; short sCount; /* init the waypoint area*/ @@ -285,7 +278,7 @@ static void data_write() waypt_disp_all(holux_disp); - iWritten = gbfwrite(HxWFile, 1, GM100_WPO_FILE_SIZE,file_out); + int iWritten = gbfwrite(HxWFile, 1, GM100_WPO_FILE_SIZE,file_out); if (iWritten == 0) { fatal(MYNAME ": Error writing data to %s.\n", file_out->name); } diff --git a/html.cc b/html.cc index 2e20c5950..ad191a28e 100644 --- a/html.cc +++ b/html.cc @@ -81,9 +81,9 @@ wr_deinit() static void html_disp(const Waypoint* wpt) { - char* cout; int32_t utmz; - double utme, utmn; + double utme; + double utmn; char utmzc; @@ -93,7 +93,7 @@ html_disp(const Waypoint* wpt) gbfprintf(file_out, "\n
\n", CSTRc(wpt->shortname)); gbfprintf(file_out, "\n"); gbfprintf(file_out, "

%s - ",(global_opts.synthesize_shortnames) ? CSTRc(mkshort_from_wpt(mkshort_handle, wpt)) : CSTRc(wpt->shortname)); - cout = pretty_deg_format(wpt->latitude, wpt->longitude, degformat[2], " ", 1); + char* cout = pretty_deg_format(wpt->latitude, wpt->longitude, degformat[2], " ", 1); gbfprintf(file_out, "%s (%d%c %6.0f %7.0f)", cout, utmz, utmzc, utme, utmn); xfree(cout); if (wpt->altitude != unknown_alt) { diff --git a/humminbird.cc b/humminbird.cc index 63bd4192d..d3c13ffb2 100644 --- a/humminbird.cc +++ b/humminbird.cc @@ -265,9 +265,6 @@ static void humminbird_read_wpt(gbfile* fin) { humminbird_waypt_t w; - double guder; - int num_icons; - Waypoint* wpt; if (! gbfread(&w, 1, sizeof(w), fin)) { fatal(MYNAME ": Unexpected end of file!\n"); @@ -283,7 +280,7 @@ humminbird_read_wpt(gbfile* fin) /* All right! Copy the data to the gpsbabel struct... */ - wpt = new Waypoint; + Waypoint* wpt = new Waypoint; // Could probably find a way to eliminate the alloc/copy. char* s = xstrndup(w.name, sizeof(w.name)); @@ -292,7 +289,7 @@ humminbird_read_wpt(gbfile* fin) wpt->SetCreationTime(w.time); - guder = gudermannian_i1924(w.north); + double guder = gudermannian_i1924(w.north); wpt->latitude = geocentric_to_geodetic_hwr(guder); wpt->longitude = (double)w.east / EAST_SCALE * 180.0; @@ -302,7 +299,7 @@ humminbird_read_wpt(gbfile* fin) WAYPT_SET(wpt,depth,(double)w.depth / 100.0); } - num_icons = sizeof(humminbird_icons) / sizeof(humminbird_icons[0]); + int num_icons = sizeof(humminbird_icons) / sizeof(humminbird_icons[0]); if (w.icon < num_icons) { wpt->icon_descr = humminbird_icons[w.icon]; } @@ -375,12 +372,6 @@ humminbird_read_track(gbfile* fin) { humminbird_trk_header_t th; - humminbird_trk_point_t* points; - route_head* trk; - Waypoint* first_wpt; - int32_t accum_east; - int32_t accum_north; - double g_lat; if (! gbfread(&th, 1, sizeof(th), fin)) { fatal(MYNAME ": Unexpected end of file reading header!\n"); @@ -413,15 +404,15 @@ humminbird_read_track(gbfile* fin) /* num_points is actually one too big, because it includes the value in the header. But we want the extra point at the end because the freak-value filter below looks at points[i+1] */ - points = (humminbird_trk_point_t*) xcalloc(th.num_points, sizeof(humminbird_trk_point_t)); + humminbird_trk_point_t* points = (humminbird_trk_point_t*) xcalloc(th.num_points, sizeof(humminbird_trk_point_t)); if (! gbfread(points, sizeof(humminbird_trk_point_t), th.num_points-1, fin)) { fatal(MYNAME ": Unexpected end of file reading points!\n"); } - accum_east = th.start_east; - accum_north = th.start_north; + int32_t accum_east = th.start_east; + int32_t accum_north = th.start_north; - trk = route_head_alloc(); + route_head* trk = route_head_alloc(); track_add_head(trk); // TODO: find a way to eliminate the copy. @@ -432,8 +423,8 @@ humminbird_read_track(gbfile* fin) /* We create one wpt for the info in the header */ - first_wpt = new Waypoint; - g_lat = gudermannian_i1924(accum_north); + Waypoint* first_wpt = new Waypoint; + double g_lat = gudermannian_i1924(accum_north); first_wpt->latitude = geocentric_to_geodetic_hwr(g_lat); first_wpt->longitude = accum_east/EAST_SCALE * 180.0; first_wpt->altitude = 0.0; @@ -442,8 +433,6 @@ humminbird_read_track(gbfile* fin) for (int i = 0 ; ilatitude = geocentric_to_geodetic_hwr(guder); wpt->longitude = accum_east/EAST_SCALE * 180.0; wpt->altitude = 0.0; @@ -494,12 +483,6 @@ humminbird_read_track_old(gbfile* fin) { humminbird_trk_header_old_t th; - humminbird_trk_point_old_t* points; - route_head* trk; - Waypoint* first_wpt; - int32_t accum_east; - int32_t accum_north; - double g_lat; const int file_len = 8048; char namebuf[TRK_NAME_LEN]; @@ -528,15 +511,15 @@ humminbird_read_track_old(gbfile* fin) /* num_points is actually one too big, because it includes the value in the header. But we want the extra point at the end because the freak-value filter below looks at points[i+1] */ - points = (humminbird_trk_point_old_t*)xcalloc(th.num_points, sizeof(humminbird_trk_point_old_t)); + humminbird_trk_point_old_t* points = (humminbird_trk_point_old_t*)xcalloc(th.num_points, sizeof(humminbird_trk_point_old_t)); if (! gbfread(points, sizeof(humminbird_trk_point_old_t), th.num_points-1, fin)) { fatal(MYNAME ": Unexpected end of file reading points!\n"); } - accum_east = th.start_east; - accum_north = th.start_north; + int32_t accum_east = th.start_east; + int32_t accum_north = th.start_north; - trk = route_head_alloc(); + route_head* trk = route_head_alloc(); track_add_head(trk); /* The name is not in the header, but at the end of the file. @@ -550,8 +533,8 @@ humminbird_read_track_old(gbfile* fin) /* We create one wpt for the info in the header */ - first_wpt = new Waypoint; - g_lat = gudermannian_i1924(accum_north); + Waypoint* first_wpt = new Waypoint; + double g_lat = gudermannian_i1924(accum_north); first_wpt->latitude = geocentric_to_geodetic_hwr(g_lat); first_wpt->longitude = accum_east/EAST_SCALE * 180.0; first_wpt->altitude = 0.0; @@ -559,8 +542,6 @@ humminbird_read_track_old(gbfile* fin) for (int i = 0 ; ilatitude = geocentric_to_geodetic_hwr(guder); wpt->longitude = accum_east/EAST_SCALE * 180.0; wpt->altitude = 0.0; @@ -608,9 +589,7 @@ static void humminbird_read() { while (! gbfeof(fin)) { - uint32_t signature; - - signature = gbfgetuint32(fin); + uint32_t signature = gbfgetuint32(fin); switch (signature) { case WPT_MAGIC: @@ -685,7 +664,6 @@ static void humminbird_write_waypoint(const Waypoint* wpt) { humminbird_waypt_t hum; - double lat, north, east; int num_icons = sizeof(humminbird_icons) / sizeof(humminbird_icons[0]); be_write16(&hum.num, waypoint_num++); @@ -705,9 +683,8 @@ humminbird_write_waypoint(const Waypoint* wpt) hum.icon = 0; /* i.e. "Diamond" as part of "Diamond, Green" or "Green Diamond" */ for (int i = 0; i < num_icons; i++) { char* match; - int j; xasprintf(&match, "*%s*", humminbird_icons[i]); - j = wpt->icon_descr.compare(match, Qt::CaseInsensitive); + int j = wpt->icon_descr.compare(match, Qt::CaseInsensitive); xfree(match); if (j != 0) { hum.icon = i; @@ -722,17 +699,16 @@ humminbird_write_waypoint(const Waypoint* wpt) be_write32(&hum.time, wpt->GetCreationTime().toTime_t()); - east = wpt->longitude / 180.0 * EAST_SCALE; + double east = wpt->longitude / 180.0 * EAST_SCALE; be_write32(&hum.east, si_round((east))); - lat = geodetic_to_geocentric_hwr(wpt->latitude); - north = inverse_gudermannian_i1924(lat); + double lat = geodetic_to_geocentric_hwr(wpt->latitude); + double north = inverse_gudermannian_i1924(lat); be_write32(&hum.north, si_round(north)); - QString name; - name = (global_opts.synthesize_shortnames) - ? mkshort_from_wpt(wptname_sh, wpt) - : mkshort(wptname_sh, wpt->shortname); + QString name = (global_opts.synthesize_shortnames) + ? mkshort_from_wpt(wptname_sh, wpt) + : mkshort(wptname_sh, wpt->shortname); memset(&hum.name, 0, sizeof(hum.name)); memcpy(&hum.name, CSTR(name), name.length()); @@ -755,11 +731,10 @@ humminbird_track_head(const route_head* trk) trk_head = nullptr; last_time = 0; if (trk->rte_waypt_ct > 0) { - QString name; trk_head = (humminbird_trk_header_t*) xcalloc(1, sizeof(humminbird_trk_header_t)); trk_points = (humminbird_trk_point_t*) xcalloc(max_points, sizeof(humminbird_trk_point_t)); - name = mkshort(trkname_sh, trk->rte_name); + QString name = mkshort(trkname_sh, trk->rte_name); strncpy(trk_head->name, CSTR(name), sizeof(trk_head->name)-1); be_write16(&trk_head->trk_num, trk->rte_num); } @@ -805,19 +780,15 @@ humminbird_track_tail(const route_head*) static void humminbird_track_cb(const Waypoint* wpt) { - int32_t north, east; - double lat; - int i; - if (trk_head == nullptr) { return; } - i = trk_head->num_points; + int i = trk_head->num_points; - east = si_round(wpt->longitude / 180.0 * EAST_SCALE); - lat = geodetic_to_geocentric_hwr(wpt->latitude); - north = si_round(inverse_gudermannian_i1924(lat)); + int32_t east = si_round(wpt->longitude / 180.0 * EAST_SCALE); + double lat = geodetic_to_geocentric_hwr(wpt->latitude); + int32_t north = si_round(inverse_gudermannian_i1924(lat)); if (wpt->creation_time.isValid()) { last_time = wpt->GetCreationTime().toTime_t(); @@ -918,12 +889,10 @@ humminbird_rte_tail(const route_head* rte) static void humminbird_write_rtept(const Waypoint* wpt) { - int i; - if (humrte == nullptr) { return; } - i = gb_ptr2int(wpt->extra_data); + int i = gb_ptr2int(wpt->extra_data); if (i <= 0) { return; } diff --git a/igc.cc b/igc.cc index 8ee7b4262..c5532acad 100644 --- a/igc.cc +++ b/igc.cc @@ -94,7 +94,6 @@ static unsigned char coords_match(double lat1, double lon1, double lat2, double */ static igc_rec_type_t get_record(char** rec) { - size_t len; char* c; retry: *rec = c = gbfgetstr(file_in); @@ -105,7 +104,7 @@ retry: return rec_none; } - len = strlen(c); + size_t len = strlen(c); /* Trackwiev writes (bogus) blank links between each record */ if (len == 0) { @@ -162,7 +161,6 @@ static void igc_task_rec(const char* rec) char task_num[5]; char task_desc[MAXRECLEN]; - Waypoint* wpt; unsigned int lat_deg, lat_min, lat_frac; unsigned int lon_deg, lon_min, lon_frac; char lat_hemi[2], lon_hemi[2]; @@ -204,7 +202,7 @@ static void igc_task_rec(const char* rec) fatal(MYNAME ": task waypoint (C) record parse error\n%s", rec); } - wpt = new Waypoint; + Waypoint* wpt = new Waypoint; wpt->latitude = ('N' == lat_hemi[0] ? 1 : -1) * (lat_deg + (lat_min * 1000 + lat_frac) / 1000.0 / 60); @@ -261,7 +259,6 @@ static void igc_task_rec(const char* rec) static void data_read() { char* ibuf; - igc_rec_type_t rec_type; unsigned int hours, mins, secs; unsigned int lat_deg, lat_min, lat_frac; unsigned int lon_deg, lon_min, lon_frac; @@ -286,7 +283,7 @@ static void data_read() strcpy(trk_desc, HDRMAGIC HDRDELIM); while (true) { - rec_type = get_record(&ibuf); + igc_rec_type_t rec_type = get_record(&ibuf); switch (rec_type) { case rec_manuf_id: // Manufacturer/ID record already found in rd_init(). @@ -544,10 +541,8 @@ static char* latlon2str(const Waypoint* wpt) long lon_milliminutes = lround(wpt->longitude * 60000.0); char lat_hemi = lat_milliminutes < 0 ? 'S' : 'N'; char lon_hemi = lon_milliminutes < 0 ? 'W' : 'E'; - ldiv_t lat_digits; - ldiv_t lon_digits; - lat_digits = ldiv(labs(lat_milliminutes), 60000L); - lon_digits = ldiv(labs(lon_milliminutes), 60000L); + ldiv_t lat_digits = ldiv(labs(lat_milliminutes), 60000L); + ldiv_t lon_digits = ldiv(labs(lon_milliminutes), 60000L); if (snprintf(str, 18, "%02ld%05ld%c%03ld%05ld%c", lat_digits.quot, lat_digits.rem, lat_hemi, lon_digits.quot, lon_digits.rem, lon_hemi) != 17) { @@ -655,7 +650,6 @@ static void wr_task_wpt_name(const Waypoint* wpt, const char* alt_name) static void wr_task_hdr(const route_head* rte) { unsigned char have_takeoff = 0; - const Waypoint* wpt; char flight_date[7] = "000000"; char task_desc[MAXRECLEN] = ""; int num_tps = rte->rte_waypt_ct - 2; @@ -668,7 +662,7 @@ static void wr_task_hdr(const route_head* rte) } // See if the takeoff and landing waypoints are there or if we need to // generate them. - wpt = (Waypoint*) QUEUE_LAST(&rte->waypoint_list); + const Waypoint* wpt = (Waypoint*) QUEUE_LAST(&rte->waypoint_list); if (wpt->shortname.startsWith("LANDING")) { num_tps--; } @@ -728,10 +722,8 @@ static void wr_tasks() */ static void wr_fix_record(const Waypoint* wpt, int pres_alt, int gnss_alt) { - struct tm* tm; - const time_t tt = wpt->GetCreationTime().toTime_t(); - tm = gmtime(&tt); + struct tm* tm = gmtime(&tt); if (nullptr == tm) { fatal(MYNAME ": bad track timestamp\n"); @@ -757,17 +749,16 @@ static void wr_fix_record(const Waypoint* wpt, int pres_alt, int gnss_alt) */ static int correlate_tracks(const route_head* pres_track, const route_head* gnss_track) { - const queue* elem; - double last_alt, alt_diff; + double alt_diff; double speed; - time_t pres_time, gnss_time; + time_t pres_time; + time_t gnss_time; int time_diff; - const Waypoint* wpt; // Deduce the landing time from the pressure altitude track based on // when we last descended to within 10m of the final track altitude. - elem = QUEUE_LAST(&pres_track->waypoint_list); - last_alt = ((Waypoint*) elem)->altitude; + const queue* elem = QUEUE_LAST(&pres_track->waypoint_list); + double last_alt = ((Waypoint*) elem)->altitude; do { elem = elem->prev; if (&pres_track->waypoint_list == elem) { @@ -789,7 +780,7 @@ static int correlate_tracks(const route_head* pres_track, const route_head* gnss elem = QUEUE_LAST(&gnss_track->waypoint_list); last_alt = ((Waypoint*) elem)->altitude; do { - wpt = (Waypoint*) elem; + const Waypoint* wpt = (Waypoint*) elem; elem = elem->prev; if (&gnss_track->waypoint_list == elem) { // No track left @@ -825,10 +816,7 @@ static double interpolate_alt(const route_head* track, time_t time) { static const queue* prev_elem = nullptr; static const queue* curr_elem = nullptr; - const Waypoint* prev_wpt; - const Waypoint* curr_wpt; int time_diff; - double alt_diff; // Start search at the beginning of the track if (!prev_elem) { @@ -844,8 +832,8 @@ static double interpolate_alt(const route_head* track, time_t time) curr_elem = QUEUE_NEXT(prev_elem); } - prev_wpt = (Waypoint*) prev_elem; - curr_wpt = (Waypoint*) curr_elem; + const Waypoint* prev_wpt = (Waypoint*) prev_elem; + const Waypoint* curr_wpt = (Waypoint*) curr_elem; if (QUEUE_FIRST(&track->waypoint_list) == curr_elem) { if (curr_wpt->GetCreationTime().toTime_t() == time) { @@ -861,7 +849,7 @@ static double interpolate_alt(const route_head* track, time_t time) // Avoid divide by zero return curr_wpt->altitude; } - alt_diff = curr_wpt->altitude - prev_wpt->altitude; + double alt_diff = curr_wpt->altitude - prev_wpt->altitude; return prev_wpt->altitude + (alt_diff / time_diff) * (time - prev_wpt->GetCreationTime().toTime_t()); } diff --git a/igo8.cc b/igo8.cc index 1b82e9818..d464bdb95 100644 --- a/igo8.cc +++ b/igo8.cc @@ -150,17 +150,15 @@ static void igo8_read_init(const QString& fname) // Reader callback static void igo8_read() { - Waypoint* wpt_tmp; - route_head* track_head; igo8_point point; - track_head = route_head_alloc(); + route_head* track_head = route_head_alloc(); track_add_head(track_head); while (in_point_count && gbfread(&point, sizeof(point), 1, igo8_file_in) > 0) { in_point_count--; - wpt_tmp = new Waypoint; + Waypoint* wpt_tmp = new Waypoint; wpt_tmp->latitude = le_read32(&point.lat) / (double)0x800000; wpt_tmp->longitude = le_read32(&point.lon) / (double)0x800000; @@ -279,10 +277,9 @@ static unsigned int print_unicode(char* dst, const unsigned int dst_max_length, static unsigned int ascii_to_unicode_2(char* dst, const unsigned int dst_max_length, const char* src) { - short* unicode; int len; - unicode = cet_str_any_to_uni(src, &cet_cs_vec_ansi_x3_4_1968, &len); + short* unicode = cet_str_any_to_uni(src, &cet_cs_vec_ansi_x3_4_1968, &len); len *= 2; /* real size in bytes */ len = print_unicode(dst, dst_max_length, unicode, len); diff --git a/inifile.cc b/inifile.cc index f24233d6a..831ee9e48 100644 --- a/inifile.cc +++ b/inifile.cc @@ -64,11 +64,9 @@ find_gpsbabel_inifile(const QString& path) /* can be empty or NULL */ static gbfile* open_gpsbabel_inifile() { - QString name; - QString envstr; gbfile* res = nullptr; - envstr = ugetenv("GPSBABELINI"); + QString envstr = ugetenv("GPSBABELINI"); if (!envstr.isNull()) { if (QFile(envstr).open(QIODevice::ReadOnly)) { return gbfopen(envstr, "r", "GPSBabel"); @@ -76,7 +74,7 @@ open_gpsbabel_inifile() warning("WARNING: GPSBabel-inifile, defined in environment, NOT found!\n"); return nullptr; } - name = find_gpsbabel_inifile(""); // Check in current directory first. + QString name = find_gpsbabel_inifile(""); // Check in current directory first. if (name.isNull()) { #ifdef __WIN32__ // Use &&'s early-out behaviour to try successive file locations: first @@ -141,19 +139,16 @@ inifile_load_file(gbfile* fin, inifile_t* inifile, const char* myname) ENQUEUE_TAIL(&inifile->secs, &sec->Q); inifile->isecs++; } else { - char* cx; - inifile_entry_t* entry; - if (sec == nullptr) { fatal("%s: missing section header in '%s'.\n", myname, qPrintable(gbinipathname)); } - entry = (inifile_entry_t*) xcalloc(1, sizeof(*entry)); + inifile_entry_t* entry = (inifile_entry_t*) xcalloc(1, sizeof(*entry)); ENQUEUE_TAIL(&sec->entries, &entry->Q); sec->ientries++; - cx = strchr(cin, '='); + char* cx = strchr(cin, '='); if (cx != nullptr) { *cx = '\0'; cin = lrtrim(cin); @@ -210,7 +205,6 @@ inifile_find_value(const inifile_t* inifile, const char* sec_name, const char* k inifile_t* inifile_init(const QString& filename, const char* myname) { - inifile_t* result; gbfile* fin = nullptr; if (filename.isEmpty()) { @@ -222,7 +216,7 @@ inifile_init(const QString& filename, const char* myname) fin = gbfopen(filename, "rb", myname); } - result = (inifile_t*) xcalloc(1, sizeof(*result)); + inifile_t* result = (inifile_t*) xcalloc(1, sizeof(*result)); QUEUE_INIT(&result->secs); inifile_load_file(fin, result, myname); @@ -305,9 +299,7 @@ inifile_readstr(const inifile_t* inifile, const char* section, const char* key) int inifile_readint(const inifile_t* inifile, const char* section, const char* key, int* value) { - char* str; - - str = inifile_find_value(inifile, section, key); + char* str = inifile_find_value(inifile, section, key); if (str == nullptr) { return 0; diff --git a/interpolate.cc b/interpolate.cc index 219a238f4..e98beb50f 100644 --- a/interpolate.cc +++ b/interpolate.cc @@ -36,10 +36,6 @@ void InterpolateFilter::process() double lat1 = 0, lon1 = 0; double altitude1 = unknown_alt; unsigned int time1 = 0; - unsigned int timen; - double distn; - double curdist; - double rt1, rn1, rt2, rn2; double frac; if (opt_route) { @@ -75,7 +71,7 @@ void InterpolateFilter::process() } else { if (opt_interval && wpt->creation_time.toTime_t() - time1 > interval) { - for (timen = time1+interval; + for (unsigned int timen = time1+interval; timen < wpt->creation_time.toTime_t(); timen += interval) { Waypoint* wpt_new = new Waypoint(*wpt); @@ -99,14 +95,14 @@ void InterpolateFilter::process() } } } else if (opt_dist) { - rt1 = RAD(lat1); - rn1 = RAD(lon1); - rt2 = RAD(wpt->latitude); - rn2 = RAD(wpt->longitude); - curdist = gcdist(rt1, rn1, rt2, rn2); + double rt1 = RAD(lat1); + double rn1 = RAD(lon1); + double rt2 = RAD(wpt->latitude); + double rn2 = RAD(wpt->longitude); + double curdist = gcdist(rt1, rn1, rt2, rn2); curdist = radtomiles(curdist); if (curdist > dist) { - for (distn = dist; + for (double distn = dist; distn < curdist; distn += dist) { Waypoint* wpt_new = new Waypoint(*wpt); diff --git a/itracku.cc b/itracku.cc index 11ea4d1c5..61f964ca5 100644 --- a/itracku.cc +++ b/itracku.cc @@ -138,8 +138,6 @@ itracku_device_update_data_init() static int itracku_device_update_data_read(void* buf, int len) { - int rc; - if (update_data_buffer_write - update_data_buffer_read >= len) { memcpy(buf, update_data_buffer_read, len); update_data_buffer_read += len; @@ -152,7 +150,7 @@ itracku_device_update_data_read(void* buf, int len) update_data_buffer_read = update_data_buffer; } - rc = gbser_read_wait(fd, update_data_buffer_write, update_data_buffer_end - update_data_buffer_write, timeout); + int rc = gbser_read_wait(fd, update_data_buffer_write, update_data_buffer_end - update_data_buffer_write, timeout); if (rc == gbser_ERROR) { return 0; } @@ -202,9 +200,6 @@ static double deg_min_to_deg(volatile uint32_t x) { double sign; - uint32_t sep; - uint32_t d; - uint32_t m10000; // determine the sign if (x > 0x80000000) { sign = -1.0; @@ -213,12 +208,12 @@ deg_min_to_deg(volatile uint32_t x) sign = 1.0; } - sep = 1000000; + uint32_t sep = 1000000; // extract degrees - d = (unsigned int) x / (unsigned int) sep; + uint32_t d = (unsigned int) x / (unsigned int) sep; // extract (minutes * 10000) - m10000 = x - d * sep; + uint32_t m10000 = x - d * sep; // convert minutes and degrees to a double return sign * ((double)d + ((double)m10000) / 600000.0); @@ -231,8 +226,6 @@ static uint32_t deg_to_deg_min(double x) { int32_t sign; - double d; - double f; // determine sign if (x >= 0) { @@ -243,10 +236,10 @@ deg_to_deg_min(double x) } // integer degrees - d = floor(x); + double d = floor(x); // fractional part - f = x - d; + double f = x - d; return (uint32_t)d * 1000000 + // multiply integer degrees to shift it to the right digits. @@ -295,8 +288,7 @@ encode_itracku_time(time_t time) static Waypoint* to_waypoint(itracku_data_record* d) { - Waypoint* wp; - wp = new Waypoint; + Waypoint* wp = new Waypoint; wp->longitude = deg_min_to_deg(le_read32(d->longitude)); wp->latitude = deg_min_to_deg(le_read32(d->latitude)); wp->SetCreationTime(decode_itracku_time(le_read32(d->creation_time))); @@ -328,14 +320,13 @@ static int init_device() { int rc; - const char* greeting; // verify that we have a MTK based logger... dbg(1, "verifying device on port %s", port); itracku_device_write_string("WP AP-Exit"); gbser_flush(fd); itracku_device_write_string("W'P Camera Detect"); - greeting = itracku_device_read_string(); + const char* greeting = itracku_device_read_string(); if (0 == strcmp(greeting , "WP GPS+BT")) { dbg(1, "device recognised on port %s", port); @@ -540,8 +531,7 @@ static uint32_t itracku_file_read_last_time(gbfile* fin) { itracku_data_record d; - gbsize_t s; - s = sizeof(itracku_data_record); + gbsize_t s = sizeof(itracku_data_record); gbfseek(fin, 0, SEEK_END); if (gbftell(fin) < s) { return 0; @@ -686,8 +676,6 @@ gprmc_parse(char* ibuf) char fix; unsigned int dmy; double speed,course; - Waypoint* waypt; - double fsec; struct tm tm; int rc = sscanf(ibuf,"$GPRMC,%lf,%c,%lf,%c,%lf,%c,%lf,%lf,%u", @@ -699,7 +687,7 @@ gprmc_parse(char* ibuf) return nullptr; } - fsec = hms - (int)hms; + double fsec = hms - (int)hms; tm.tm_sec = (long) hms % 100; hms = hms / 100; @@ -713,7 +701,7 @@ gprmc_parse(char* ibuf) dmy = dmy / 100; tm.tm_mday = dmy; - waypt = new Waypoint; + Waypoint* waypt = new Waypoint; WAYPT_SET(waypt, speed, KNOTS_TO_MPS(speed)); @@ -745,11 +733,10 @@ static Waypoint* itracku_rt_position(posn_status*) { char line[1024]; - Waypoint* wpt; while (true) { gbser_read_line(fd, line, sizeof(line), 5000, 13, 10); dbg(1, line); - wpt = gprmc_parse(line); + Waypoint* wpt = gprmc_parse(line); if (wpt) { return wpt; } diff --git a/jtr.cc b/jtr.cc index 21a6a84c1..77c2503e9 100644 --- a/jtr.cc +++ b/jtr.cc @@ -40,10 +40,9 @@ static QHash trkpts; static time_t jtr_parse_time(const char* str, struct tm* tm, int* milli) { - long int hms; char* dot; - hms = strtol(str, &dot, 10); + long int hms = strtol(str, &dot, 10); if (hms > 0) { tm->tm_sec = hms % 100; hms = hms / 100; @@ -103,16 +102,14 @@ jtr_read() route_head* trk = nullptr; while ((str = gbfgetstr(fin))) { - Waypoint* wpt; struct tm tm; - char* tmp; char valid = 'V'; - double lat, lon; - float speed, course, mcourse, mvar, mdev; + double lon; + float course, mcourse, mvar, mdev; time_t time = 0; int mills = 0; char buf[32]; - char mvardir, mdevdir; + char mdevdir; line++; @@ -126,12 +123,12 @@ jtr_read() } memset(&tm, 0, sizeof(tm)); - lat = lon = 999; - speed = course = mcourse = mvar = mdev = -1; - mvardir = mdevdir = 0; + double lat = lon = 999; + float speed = course = mcourse = mvar = mdev = -1; + char mvardir = mdevdir = 0; int column = -1; - tmp = str; + char* tmp = str; while ((str = csv_lineparse(tmp, ",", "", column++))) { tmp = nullptr; @@ -210,7 +207,7 @@ jtr_read() continue; } - wpt = new Waypoint; + Waypoint* wpt = new Waypoint; wpt->latitude = lat; wpt->longitude = lon; diff --git a/kml.cc b/kml.cc index 40968faf6..0f2fb650c 100644 --- a/kml.cc +++ b/kml.cc @@ -224,10 +224,9 @@ static void kml_init_color_sequencer(unsigned int steps_per_rev) static void kml_step_color() { - int color_seq; // Map kml_color_sequencer.seq to an integer in the range [0, KML_COLOR_LIMIT*6). // Note that color_seq may be outside this range if the cast from float to int fails. - color_seq = ((int) kml_color_sequencer.seq) % (KML_COLOR_LIMIT * 6); + int color_seq = ((int) kml_color_sequencer.seq) % (KML_COLOR_LIMIT * 6); if (global_opts.debug_level >= 1) { printf(MYNAME ": kml_color_sequencer seq %f %d, step %f\n",kml_color_sequencer.seq, color_seq, kml_color_sequencer.step); } @@ -470,16 +469,14 @@ void gx_trk_when(xg_string args, const QXmlStreamAttributes*) void gx_trk_coord(xg_string args, const QXmlStreamAttributes*) { - Waypoint* trkpt; double lat, lon, alt; - int n; if (! gx_trk_times || gx_trk_times->isEmpty()) { fatal(MYNAME ": There were more gx:coord elements than the number of when elements.\n"); } - trkpt = new Waypoint; + Waypoint* trkpt = new Waypoint; trkpt->SetCreationTime(gx_trk_times->takeFirst()); - n = sscanf(CSTR(args), "%lf %lf %lf", &lon, &lat, &alt); + int n = sscanf(CSTR(args), "%lf %lf %lf", &lon, &lat, &alt); // Empty gx_coord elements are allowed to balance the number of when elements, // but if we get one we will throw away the time as we don't have a location. // It is not clear that coord elements without altitude are allowed, but our @@ -740,11 +737,8 @@ static void kml_output_trkdescription(const route_head* header, computed_trkdata* td) { const char* max_alt_units; - double max_alt; const char* min_alt_units; - double min_alt; const char* distance_units; - double distance; if (!td || !trackdata) { return; @@ -753,9 +747,9 @@ void kml_output_trkdescription(const route_head* header, computed_trkdata* td) QString hstring; gpsbabel::XmlStreamWriter hwriter(&hstring); - max_alt = fmt_altitude(td->max_alt, &max_alt_units); - min_alt = fmt_altitude(td->min_alt, &min_alt_units); - distance = fmt_distance(td->distance_meters, &distance_units); + double max_alt = fmt_altitude(td->max_alt, &max_alt_units); + double min_alt = fmt_altitude(td->min_alt, &min_alt_units); + double distance = fmt_distance(td->distance_meters, &distance_units); writer->writeEmptyElement(QStringLiteral("snippet")); @@ -806,8 +800,7 @@ void kml_output_trkdescription(const route_head* header, computed_trkdata* td) kml_td(hwriter, QStringLiteral("Max Cadence"), QStringLiteral(" %1 rpm ").arg(QString::number(td->max_cad))); } if (td->start && td->end) { - gpsbabel::DateTime t; - t = QDateTime::fromTime_t(td->start); + gpsbabel::DateTime t = QDateTime::fromTime_t(td->start); if (t.isValid()) { kml_td(hwriter, QStringLiteral("Start Time"), t.toPrettyString()); } @@ -829,8 +822,7 @@ void kml_output_trkdescription(const route_head* header, computed_trkdata* td) if (td->start && td->end) { writer->writeStartElement(QStringLiteral("TimeSpan")); - gpsbabel::DateTime t; - t = QDateTime::fromTime_t(td->start); + gpsbabel::DateTime t = QDateTime::fromTime_t(td->start); writer->writeTextElement(QStringLiteral("begin"), t.toPrettyString()); t = QDateTime::fromTime_t(td->end); writer->writeTextElement(QStringLiteral("end"), t.toPrettyString()); @@ -920,7 +912,6 @@ static void kml_output_positioning(bool tessellate) static void kml_output_description(const Waypoint* pt) { const char* alt_units; - double alt; if (!trackdata) { return; @@ -929,7 +920,7 @@ static void kml_output_description(const Waypoint* pt) QString hstring; gpsbabel::XmlStreamWriter hwriter(&hstring); - alt = fmt_altitude(pt->altitude, &alt_units); + double alt = fmt_altitude(pt->altitude, &alt_units); writer->writeStartElement(QStringLiteral("description")); hwriter.writeCharacters(QStringLiteral("\n")); @@ -1896,8 +1887,6 @@ static void kml_route_tlr(const route_head* header) // to include all our data. static void kml_write_AbstractView() { - double bb_size; - // Make a pass through all the points to find the bounds. if (waypt_count()) { waypt_disp_all(kml_add_to_bounds); @@ -1917,7 +1906,6 @@ static void kml_write_AbstractView() writer->writeTextElement(QStringLiteral("begin"), kml_time_min.toPrettyString()); } if (kml_time_max.isValid()) { - gpsbabel::DateTime time_max; // In realtime tracking mode, we fudge the end time by a few minutes // to ensure that the freshest data (our current location) is contained // within the timespan. Earth's time may not match the GPS because @@ -1925,7 +1913,7 @@ static void kml_write_AbstractView() // the network position. So we shove the end of the timespan out to // ensure the right edge of that time slider includes us. // - time_max = realtime_positioning ? kml_time_max.addSecs(600) : kml_time_max; + gpsbabel::DateTime time_max = realtime_positioning ? kml_time_max.addSecs(600) : kml_time_max; writer->writeTextElement(QStringLiteral("end"), time_max.toPrettyString()); } writer->writeEndElement(); // Close gx:TimeSpan tag @@ -1943,8 +1931,8 @@ static void kml_write_AbstractView() // It turns out the length of the diagonal of the bounding box gives us a // reasonable guess for setting the camera altitude. - bb_size = gcgeodist(kml_bounds.min_lat, kml_bounds.min_lon, - kml_bounds.max_lat, kml_bounds.max_lon); + double bb_size = gcgeodist(kml_bounds.min_lat, kml_bounds.min_lon, + kml_bounds.max_lat, kml_bounds.max_lon); // Clamp bottom zoom level. Otherwise, a single point zooms to grass. if (bb_size < 1000) { bb_size = 1000; diff --git a/lmx.cc b/lmx.cc index 217d68b12..8dd57a5ac 100644 --- a/lmx.cc +++ b/lmx.cc @@ -195,13 +195,10 @@ lmx_write_xml(int tag, const QString& data, int indent) static void lmx_print(const Waypoint* wpt) { - QString oname; - QString odesc; - /* * Desparation time, try very hard to get a good shortname */ - odesc = wpt->notes; + QString odesc = wpt->notes; if (odesc.isEmpty()) { odesc = wpt->description; } @@ -209,7 +206,7 @@ lmx_print(const Waypoint* wpt) odesc = wpt->shortname; } - oname = global_opts.synthesize_shortnames ? odesc : wpt->shortname; + QString oname = global_opts.synthesize_shortnames ? odesc : wpt->shortname; lmx_start_tag(0x47, 2); // landmark if (!binary) { diff --git a/lowranceusr.cc b/lowranceusr.cc index 15a82ed50..c1fc04eb7 100644 --- a/lowranceusr.cc +++ b/lowranceusr.cc @@ -228,9 +228,9 @@ const time_t base_time_secs = 946706400; static int lowranceusr_readstr(char* buf, const int maxlen, gbfile* file) { - int org, len; + int len; - org = len = gbfgetint32(file); + int org = len = gbfgetint32(file); if (len < 0) { fatal(MYNAME ": Invalid item length (%d)!\n", len); } else if (len) { @@ -269,8 +269,6 @@ lowranceusr_find_desc_from_icon_number(const int icon) static int lowranceusr_find_icon_number_from_desc(const QString& desc) { - int n; - if (desc.isNull()) { return DEF_ICON; } @@ -279,7 +277,7 @@ lowranceusr_find_icon_number_from_desc(const QString& desc) * If we were given a numeric icon number as a description * (i.e. 8255), just return that. */ - n = desc.toInt(); + int n = desc.toInt(); if (n) { return n; } @@ -379,7 +377,6 @@ static void lowranceusr_parse_waypt(Waypoint* wpt_tmp) { char buff[MAXUSRSTRINGSIZE + 1]; - int text_len; wpt_tmp->latitude = lat_mm_to_deg(gbfgetint32(file_in)); wpt_tmp->longitude = lon_mm_to_deg(gbfgetint32(file_in)); @@ -388,7 +385,7 @@ lowranceusr_parse_waypt(Waypoint* wpt_tmp) wpt_tmp->altitude = unknown_alt; } - text_len = lowranceusr_readstr(&buff[0], MAXUSRSTRINGSIZE, file_in); + int text_len = lowranceusr_readstr(&buff[0], MAXUSRSTRINGSIZE, file_in); if (text_len) { buff[text_len] = '\0'; wpt_tmp->shortname = buff; @@ -446,9 +443,8 @@ static void lowranceusr_parse_routes() { char buff[MAXUSRSTRINGSIZE + 1]; - short int num_routes; - num_routes = gbfgetint16(file_in); + short int num_routes = gbfgetint16(file_in); if (global_opts.debug_level >= 1) { printf(MYNAME " parse_routes: Num Routes = %d\n", num_routes); @@ -489,9 +485,8 @@ static void lowranceusr_parse_icons() { char buff[MAXUSRSTRINGSIZE + 1]; - short int num_icons; - num_icons = gbfgetint16(file_in); + short int num_icons = gbfgetint16(file_in); if (global_opts.debug_level >= 1) { printf(MYNAME " parse_icons: num Icons = %d\n", num_icons); @@ -504,8 +499,7 @@ lowranceusr_parse_icons() /* symbol */ (void) gbfread(&buff[0], 4, 1, file_in); } else { - Waypoint* wpt_tmp; - wpt_tmp = new Waypoint; + Waypoint* wpt_tmp = new Waypoint; /* position coord lat & long */ wpt_tmp->latitude = lat_mm_to_deg(gbfgetint32(file_in)); @@ -525,11 +519,10 @@ static void lowranceusr_parse_trails() { char buff[MAXUSRSTRINGSIZE + 1]; - short int num_trails, num_section_points; int trk_num; /* num trails */ - num_trails = gbfgetint16(file_in); + short int num_trails = gbfgetint16(file_in); if (global_opts.debug_level >= 1) { printf(MYNAME " parse_trails: num trails = %d\n", num_trails); @@ -576,7 +569,7 @@ lowranceusr_parse_trails() while (num_trail_points && !gbfeof(file_in)) { /* num section points */ - num_section_points = gbfgetint16(file_in); + short int num_section_points = gbfgetint16(file_in); if (global_opts.debug_level >= 1) { printf(MYNAME " parse_trails: num section points = %d\n", num_section_points); @@ -640,9 +633,7 @@ data_read() } for (int i = 0; i < NumWaypoints && !gbfeof(file_in); i++) { - Waypoint* wpt_tmp; - - wpt_tmp = new Waypoint; + Waypoint* wpt_tmp = new Waypoint; /* Object num */ short object_num = gbfgetint16(file_in); @@ -664,16 +655,15 @@ data_read() static void lowranceusr_waypt_disp(const Waypoint* wpt) { - int text_len, Lat, Lon, Time, SymbolId; - short int WayptType; + int Time, SymbolId; int alt = METERS_TO_FEET(wpt->altitude); if (wpt->altitude == unknown_alt) { alt = UNKNOWN_USR_ALTITUDE; } - Lat = lat_deg_to_mm(wpt->latitude); - Lon = lon_deg_to_mm(wpt->longitude); + int Lat = lat_deg_to_mm(wpt->latitude); + int Lon = lon_deg_to_mm(wpt->longitude); gbfputint32(Lat, file_out); gbfputint32(Lon, file_out); gbfputint32(alt, file_out); @@ -710,7 +700,7 @@ lowranceusr_waypt_disp(const Waypoint* wpt) name = wpt->shortname; } - text_len = name.length(); + int text_len = name.length(); if (text_len > MAXUSRSTRINGSIZE) { text_len = MAXUSRSTRINGSIZE; } @@ -766,7 +756,7 @@ lowranceusr_waypt_disp(const Waypoint* wpt) gbfputint32(SymbolId, file_out); /* USER waypoint type */ - WayptType = 0; + short int WayptType = 0; gbfputint16(WayptType, file_out); } @@ -826,9 +816,7 @@ lowranceusr_write_icon(const Waypoint* wpt) static void lowranceusr_track_hdr(const route_head* trk) { - int text_len; QString name; - short num_trail_points, max_trail_size; char visible=1; ++trail_count; @@ -841,7 +829,7 @@ lowranceusr_track_hdr(const route_head* trk) name = name + QString("Babel %1").arg(trail_count); } - text_len = name.length(); + int text_len = name.length(); if (text_len > MAXUSRSTRINGSIZE) { text_len = MAXUSRSTRINGSIZE; } @@ -855,8 +843,8 @@ lowranceusr_track_hdr(const route_head* trk) } gbfwrite(CSTR(name), 1, text_len, file_out); - num_trail_points = (short) trk->rte_waypt_ct; - max_trail_size = MAX_TRAIL_POINTS; + short num_trail_points = (short) trk->rte_waypt_ct; + short max_trail_size = MAX_TRAIL_POINTS; if (num_trail_points > max_trail_size) { num_trail_points = max_trail_size; } @@ -876,7 +864,6 @@ lowranceusr_track_hdr(const route_head* trk) static void lowranceusr_route_hdr(const route_head* rte) { - int text_len; char* name, tmp_name[20]; char route_reversed=0; @@ -891,7 +878,7 @@ lowranceusr_route_hdr(const route_head* rte) snprintf(tmp_name, sizeof(tmp_name), "Babel R%u", ++lowrance_route_count); name = xstrdup(tmp_name); } - text_len = strlen(name); + int text_len = strlen(name); if (text_len > MAXUSRSTRINGSIZE) { text_len = MAXUSRSTRINGSIZE; } @@ -933,7 +920,6 @@ lowranceusr_track_disp(const Waypoint* wpt) static void lowranceusr_merge_track_hdr(const route_head* trk) { - int text_len; char* name, tmp_name[20]; if (++trail_count == 1) { @@ -946,7 +932,7 @@ lowranceusr_merge_track_hdr(const route_head* trk) snprintf(tmp_name, sizeof(tmp_name), "Babel %u", trail_count); name = xstrdup(tmp_name); } - text_len = strlen(name); + int text_len = strlen(name); if (text_len > MAXUSRSTRINGSIZE) { text_len = MAXUSRSTRINGSIZE; } @@ -994,12 +980,11 @@ lowranceusr_merge_track_hdr_2(const route_head*) static void data_write() { - short int NumWaypoints, MajorVersion, MinorVersion, NumRoutes, NumTrails; setshort_length(mkshort_handle, 15); - MajorVersion = writing_version; - MinorVersion = 0; + short int MajorVersion = writing_version; + short int MinorVersion = 0; - NumWaypoints = waypt_count(); + short int NumWaypoints = waypt_count(); gbfputint16(MajorVersion, file_out); gbfputint16(MinorVersion, file_out); @@ -1017,7 +1002,7 @@ data_write() } /* Route support added 6/21/05 */ - NumRoutes = route_count(); + short int NumRoutes = route_count(); gbfputint16(NumRoutes, file_out); if (global_opts.debug_level >= 1) { @@ -1038,7 +1023,7 @@ data_write() } /* Track support added 6/21/05 */ - NumTrails = track_count(); + short int NumTrails = track_count(); if (NumTrails && merge) { NumTrails = 1; diff --git a/lowranceusr4.cc b/lowranceusr4.cc index 310cf8fb5..1b43e703a 100644 --- a/lowranceusr4.cc +++ b/lowranceusr4.cc @@ -77,10 +77,10 @@ typedef struct { static int lowranceusr4_readstr(char* buf, const int maxlen, gbfile* file, int bytes_per_char) { - int org, len; + int len; int bytesread = 0; - org = len = gbfgetint32(file); /* bytes */ + int org = len = gbfgetint32(file); /* bytes */ if (len < 0) { buf[0] = '\0'; /* seems len=-1 means no string */ return 0; @@ -214,30 +214,28 @@ lat_deg_to_mm(double x) static time_t lowranceusr4_get_timestamp(int jd_number, time_t t) { - int a, b, c, d, e, m; - struct tm* ptm, ntm; - time_t out; + struct tm ntm; /* get UTC time from time_t */ - ptm = gmtime(&t); + struct tm* ptm = gmtime(&t); memset(&ntm, 0, sizeof(ntm)); ntm.tm_hour = ptm->tm_hour; ntm.tm_min = ptm->tm_min; ntm.tm_sec = ptm->tm_sec; /* convert the JD number to get day/month/year */ - a = jd_number + 32044; - b = (4*a + 3) / 146097; - c = a - (146097*b) / 4; - d = (4*c + 3) / 1461; - e = c - (1461*d) / 4; - m = (5*e + 2) / 153; + int a = jd_number + 32044; + int b = (4*a + 3) / 146097; + int c = a - (146097*b) / 4; + int d = (4*c + 3) / 1461; + int e = c - (1461*d) / 4; + int m = (5*e + 2) / 153; ntm.tm_mday = e + 1 - (153*m + 2) / 5; ntm.tm_mon = m + 3 - 12 * (m / 10) - 1; ntm.tm_year = 100 * b + d - 4800 + m / 10 - 1900; /* put it all back together into a unix timestamp in UTC */ - out = mkgmtime(&ntm); + time_t out = mkgmtime(&ntm); return out; } @@ -342,20 +340,16 @@ lowranceusr4_find_waypt_index(const Waypoint* wpt) static void lowranceusr4_parse_waypoints() { - short int icon_num; - unsigned int num_waypts, create_date, create_time; char buff[MAXUSRSTRINGSIZE + 1]; - num_waypts = gbfgetint32(file_in); + unsigned int num_waypts = gbfgetint32(file_in); if (global_opts.debug_level >= 1) { printf(MYNAME " parse_waypoints: Num waypoints %d\n", num_waypts); } for (unsigned int i = 0; i < num_waypts; ++i) { - Waypoint* wpt_tmp; - - wpt_tmp = new Waypoint; + Waypoint* wpt_tmp = new Waypoint; lowranceusr4_fsdata* fsdata = lowranceusr4_alloc_fsdata(); fs_chain_add(&(wpt_tmp->fs), (format_specific_data*) fsdata); @@ -413,7 +407,7 @@ lowranceusr4_parse_waypoints() icon description; however it doesn't seem that the icon ids used in usr4 match those from usr{2,3} so we need a new mapping. */ - icon_num = gbfgetint16(file_in); + short int icon_num = gbfgetint16(file_in); (void) icon_num; // Hush warning for now. /* wpt_tmp->icon_descr = lowranceusr_find_desc_from_icon_number(icon_num); */ @@ -433,8 +427,8 @@ lowranceusr4_parse_waypoints() /* Creation date/time; the date is a Julian day number, and the time is a unix timestamp. */ - create_date = gbfgetint32(file_in); - create_time = gbfgetint32(file_in); + unsigned int create_date = gbfgetint32(file_in); + unsigned int create_time = gbfgetint32(file_in); // Julian date 2440487 is 1/1/1970. If that's the date we're working // with, as a practical matter, we have no date, so don't even compute @@ -501,13 +495,9 @@ lowranceusr4_find_waypt(int uid_unit, int uid_seq_low, int uid_seq_high) static void lowranceusr4_parse_routes() { - unsigned int num_routes, text_len; - unsigned int num_legs; char buff[MAXUSRSTRINGSIZE + 1]; - Waypoint* wpt_tmp; - unsigned int uid_unit, uid_seq_low, uid_seq_high; - num_routes = gbfgetint32(file_in); + unsigned int num_routes = gbfgetint32(file_in); if (global_opts.debug_level >= 1) { printf(MYNAME " parse_routes: Num routes = %d\n", num_routes); @@ -544,13 +534,13 @@ lowranceusr4_parse_routes() gbfgetint16(file_in); /* Route name; input is 2 bytes per char, we convert to 1 */ - text_len = lowranceusr4_readstr(&buff[0], MAXUSRSTRINGSIZE, file_in, 2); + unsigned int text_len = lowranceusr4_readstr(&buff[0], MAXUSRSTRINGSIZE, file_in, 2); if (text_len) { buff[text_len] = '\0'; rte_head->rte_name = buff; } - num_legs = gbfgetint32(file_in); + unsigned int num_legs = gbfgetint32(file_in); if (global_opts.debug_level >= 1) { printf(MYNAME " parse_routes: route name=%s has %d waypoints\n", @@ -558,10 +548,10 @@ lowranceusr4_parse_routes() } for (unsigned int j = 0; j < num_legs; ++j) { - uid_unit = gbfgetint32(file_in); - uid_seq_low = gbfgetint32(file_in); - uid_seq_high = gbfgetint32(file_in); - wpt_tmp = lowranceusr4_find_waypt(uid_unit, uid_seq_low, uid_seq_high); + unsigned int uid_unit = gbfgetint32(file_in); + unsigned int uid_seq_low = gbfgetint32(file_in); + unsigned int uid_seq_high = gbfgetint32(file_in); + Waypoint* wpt_tmp = lowranceusr4_find_waypt(uid_unit, uid_seq_low, uid_seq_high); if (wpt_tmp) { if (global_opts.debug_level >= 2) { printf(MYNAME " parse_routes: added wpt %s to route %s\n", @@ -579,12 +569,11 @@ lowranceusr4_parse_routes() static void lowranceusr4_parse_trails() { - int num_trails, M, trk_num; + int trk_num; char buff[MAXUSRSTRINGSIZE + 1]; - Waypoint* wpt_tmp; /* num trails */ - num_trails = gbfgetint32(file_in); + int num_trails = gbfgetint32(file_in); if (global_opts.debug_level >= 1) { printf(MYNAME " parse_trails: num trails = %d\n", num_trails); @@ -686,7 +675,7 @@ lowranceusr4_parse_trails() } for (int j = 0; j < num_trail_pts; ++j) { - wpt_tmp = new Waypoint; + Waypoint* wpt_tmp = new Waypoint; /* Some unknown bytes */ gbfgetint16(file_in); @@ -700,7 +689,7 @@ lowranceusr4_parse_trails() wpt_tmp->latitude = gbfgetdbl(file_in) / DEGREESTORADIANS; /* Mysterious per-trackpoint data, toss it for now */ - M = gbfgetint32(file_in); + int M = gbfgetint32(file_in); for (int k = 0; k < M; ++k) { gbfgetc(file_in); gbfgetflt(file_in); @@ -720,17 +709,13 @@ lowranceusr4_parse_trails() static void data_read() { - short int MajorVersion, MinorVersion; - int text_len, DataStreamVersion; - unsigned int create_date, create_time, serial_num; - unsigned char byte; char buff[MAXUSRSTRINGSIZE + 1]; - MajorVersion = gbfgetint16(file_in); + short int MajorVersion = gbfgetint16(file_in); reading_version = MajorVersion; - MinorVersion = gbfgetint16(file_in); - DataStreamVersion = gbfgetint32(file_in); + short int MinorVersion = gbfgetint16(file_in); + int DataStreamVersion = gbfgetint32(file_in); if (global_opts.debug_level >= 1) { printf(MYNAME " data_read: Major Version %d Minor Version %d Data Stream Version %d\n", @@ -741,7 +726,7 @@ data_read() fatal(MYNAME ": input file is from an unsupported version of the USR format (must be version 4)\n"); } - text_len = lowranceusr4_readstr(&buff[0], MAXUSRSTRINGSIZE, file_in, 1); + int text_len = lowranceusr4_readstr(&buff[0], MAXUSRSTRINGSIZE, file_in, 1); if (text_len > 0 && global_opts.debug_level >= 1) { buff[text_len] = '\0'; printf(MYNAME " file title: %s\n", buff); @@ -754,14 +739,14 @@ data_read() } /* for now we won't use these for anything */ - create_date = gbfgetint32(file_in); + unsigned int create_date = gbfgetint32(file_in); (void) create_date; - create_time = gbfgetint32(file_in); + unsigned int create_time = gbfgetint32(file_in); (void) create_time; - byte = gbfgetc(file_in); /* unused, apparently */ + unsigned char byte = gbfgetc(file_in); /* unused, apparently */ (void) byte; - serial_num = gbfgetint32(file_in); + unsigned int serial_num = gbfgetint32(file_in); if (global_opts.debug_level >= 1) { printf(MYNAME " device serial number %u\n", serial_num); } @@ -886,10 +871,8 @@ lowranceusr4_write_route_hdr(const route_head* rte) static void lowranceusr4_write_wpt_uids(const Waypoint* wpt) { - int waypt_idx; - /* find the index of wpt in our table */ - waypt_idx = lowranceusr4_find_waypt_index(wpt); + int waypt_idx = lowranceusr4_find_waypt_index(wpt); if (global_opts.debug_level >= 2) { if (waypt_idx > waypt_table_ct) { printf(MYNAME " WARNING: failed finding waypoint %s in waypoint table\n", @@ -1012,17 +995,14 @@ lowranceusr4_write_trails() static void data_write() { - short int MajorVersion, MinorVersion; - int DataStreamVersion; time_t now; - struct tm* now_tm; char buf[256]; setshort_length(mkshort_handle, 15); - MajorVersion = 4; - MinorVersion = 0; - DataStreamVersion = 10; + short int MajorVersion = 4; + short int MinorVersion = 0; + int DataStreamVersion = 10; gbfputint16(MajorVersion, file_out); gbfputint16(MinorVersion, file_out); @@ -1033,7 +1013,7 @@ data_write() /* date string */ now = time(nullptr); - now_tm = gmtime(&now); + struct tm* now_tm = gmtime(&now); sprintf(buf, "%d/%d/%d", now_tm->tm_mon+1, now_tm->tm_mday, now_tm->tm_year+1900); lowranceusr4_writestr(buf, file_out, 1); diff --git a/maggeo.cc b/maggeo.cc index 6b10a43bd..10f1b065f 100644 --- a/maggeo.cc +++ b/maggeo.cc @@ -84,10 +84,7 @@ maggeo_read() char* buff; while ((buff = gbfgetstr(maggeofile_in))) { - Waypoint* wpt_tmp; - geocache_data* gcdata; char* s = nullptr; - int fld; buff = lrtrim(buff); if (*buff == '\0') { @@ -98,10 +95,10 @@ maggeo_read() } buff += 9; /* skip field no. 1 */ - fld = 1; + int fld = 1; - wpt_tmp = new Waypoint; - gcdata = wpt_tmp->AllocGCData(); + Waypoint* wpt_tmp = new Waypoint; + geocache_data* gcdata = wpt_tmp->AllocGCData(); while ((s = csv_lineparse(buff, ",", "", fld++))) { buff = nullptr; @@ -210,7 +207,7 @@ static void append(char* buf, const char* str) { - char* cleansed1, *cleansed2; + char* cleansed2; strcat(buf, ","); @@ -218,7 +215,7 @@ append(char* buf, const char* str) return; } - cleansed1 = xstrdup(str); + char* cleansed1 = xstrdup(str); #if FIRMWARE_DOES_88591 /* Actually, this function needs needs refactored... */ cleansed2 = xstrdup(cleansed1); @@ -238,20 +235,16 @@ static void maggeo_waypt_pr(const Waypoint* waypointp) { char obuf[4096]; - double ilon, ilat; - double lon, lat; - int lon_deg, lat_deg; const char* ctype = nullptr; - QString placer; - ilat = waypointp->latitude; - ilon = waypointp->longitude; + double ilat = waypointp->latitude; + double ilon = waypointp->longitude; - lon = fabs(ilon); - lat = fabs(ilat); + double lon = fabs(ilon); + double lat = fabs(ilat); - lon_deg = lon; - lat_deg = lat; + int lon_deg = lon; + int lat_deg = lat; lon = (lon - lon_deg) * 60.0; lat = (lat - lat_deg) * 60.0; @@ -272,7 +265,7 @@ maggeo_waypt_pr(const Waypoint* waypointp) QString lfounddate = maggeo_fmtdate(waypointp->gc_data->last_found); QString cname = mkshort(desc_handle, waypointp->notes.isEmpty() ? waypointp->description : waypointp->notes); - placer = waypointp->gc_data->placer; + QString placer = waypointp->gc_data->placer; /* * As of this writing on 05/04, the firmware in the units will diff --git a/magproto.cc b/magproto.cc index 70725dec2..8bb9777f6 100644 --- a/magproto.cc +++ b/magproto.cc @@ -302,7 +302,6 @@ mag_writemsg(const char* const buf) { unsigned int osum = mag_checksum(buf); int retry_cnt = 5; - int i; char obuf[1000]; if (debug_serial) { @@ -311,7 +310,7 @@ mag_writemsg(const char* const buf) retry: - i = sprintf(obuf, "$%s*%02X\r\n",buf, osum); + int i = sprintf(obuf, "$%s*%02X\r\n",buf, osum); termwrite(obuf, i); if (magrxstate == mrs_handon || magrxstate == mrs_awaiting_ack) { magrxstate = mrs_awaiting_ack; @@ -337,16 +336,14 @@ mag_writeack(int osum) { char obuf[200]; char nbuf[200]; - int i; - unsigned int nsum; if (is_file) { return; } (void) sprintf(nbuf, "PMGNCSM,%02X", osum); - nsum = mag_checksum(nbuf); - i = sprintf(obuf, "$%s*%02X\r\n",nbuf, nsum); + unsigned int nsum = mag_checksum(nbuf); + int i = sprintf(obuf, "$%s*%02X\r\n",nbuf, nsum); if (debug_serial) { warning("ACK WRITE: %s",obuf); @@ -425,9 +422,6 @@ mag_readmsg(gpsdata_type objective) { char ibuf[512]; /* oliskoli: corrupted data (I've seen descr with a lot of escaped FFFFFFFF) may need more size */ - int isz; - unsigned int isum; - char* isump; int retrycnt = 20; retry: @@ -459,7 +453,7 @@ retry: } - isz = strlen(ibuf); + int isz = strlen(ibuf); if (isz < 5) { if (debug_serial) { @@ -471,8 +465,8 @@ retry: while (!isprint(ibuf[isz])) { isz--; } - isump = &ibuf[isz-1]; - isum = strtoul(isump, nullptr,16); + char* isump = &ibuf[isz-1]; + unsigned int isum = strtoul(isump, nullptr,16); if (isum != mag_pchecksum(&ibuf[1], isz-3)) { if (debug_serial) { warning("RXERR %02x/%02x: '%s'\n", isum, mag_pchecksum(&ibuf[1],isz-5), ibuf); @@ -599,8 +593,7 @@ static QString termread(char* ibuf, int size) if (is_file) { return gbfgets(ibuf, size, magfile_h); } else { - int rc; - rc = gbser_read_line(serial_handle, ibuf, size, 2000, 0x0a, 0x0d); + int rc = gbser_read_line(serial_handle, ibuf, size, 2000, 0x0a, 0x0d); if (rc != gbser_OK) { fatal(MYNAME ": Read error\n"); } @@ -725,8 +718,6 @@ arglist_t mag_fargs[] = { static void mag_serial_init_common(const QString& portname) { - time_t now, later; - if (is_file) { return; } @@ -736,12 +727,12 @@ mag_serial_init_common(const QString& portname) mag_handon(); } - now = current_time().toTime_t(); + time_t now = current_time().toTime_t(); /* * The 315 can take up to 4.25 seconds to respond to initialization * commands. Time out on the side of caution. */ - later = now + 6; + time_t later = now + 6; got_version = 0; mag_writemsg("PMGNCMD,VERSION"); @@ -943,10 +934,10 @@ static void parse_istring(char* istring) { int f = 0; - int n,x; + int n; while (istring[0]) { char* fp = ifield[f]; - x = sscanf(istring, "%[^,]%n", fp, &n); + int x = sscanf(istring, "%[^,]%n", fp, &n); f++; if (x) { istring += n; @@ -968,17 +959,11 @@ void parse_istring(char* istring) Waypoint* mag_trkparse(char* trkmsg) { - double latdeg, lngdeg; - int alt; - char altunits; - char lngdir, latdir; - int dmy; int hms; int fracsecs; struct tm tm; - Waypoint* waypt; - waypt = new Waypoint; + Waypoint* waypt = new Waypoint; memset(&tm, 0, sizeof(tm)); @@ -987,17 +972,17 @@ mag_trkparse(char* trkmsg) * for us. */ parse_istring(trkmsg); - latdeg = atof(ifield[1]); - latdir = ifield[2][0]; - lngdeg = atof(ifield[3]); - lngdir = ifield[4][0]; - alt = atof(ifield[5]); - altunits = ifield[6][0]; + double latdeg = atof(ifield[1]); + char latdir = ifield[2][0]; + double lngdeg = atof(ifield[3]); + char lngdir = ifield[4][0]; + int alt = atof(ifield[5]); + char altunits = ifield[6][0]; (void)altunits; sscanf(ifield[7], "%d.%d", &hms, &fracsecs); /* Field 8 is constant */ /* Field nine is optional track name */ - dmy = atoi(ifield[10]); + int dmy = atoi(ifield[10]); tm.tm_sec = hms % 100; hms = hms / 100; @@ -1054,12 +1039,10 @@ mag_rteparse(char* rtemsg) /* Explorist has a route name here */ QString rte_name; if (explorist) { - char* ca, *ce; - - ca = rtemsg + n; + char* ca = rtemsg + n; is_fatal(*ca++ != ',', MYNAME ": Incorrectly formatted route line '%s'", rtemsg); - ce = strchr(ca, ','); + char* ce = strchr(ca, ','); is_fatal(ce == nullptr, MYNAME ": Incorrectly formatted route line '%s'", rtemsg); if (ca == ce) { @@ -1130,9 +1113,8 @@ mag_rteparse(char* rtemsg) */ if (frag == mag_rte_head->nelems) { queue* elem, *tmp; - route_head* rte_head; - rte_head = route_head_alloc(); + route_head* rte_head = route_head_alloc(); route_add_head(rte_head); rte_head->rte_num = rtenum; rte_head->rte_name = rte_name; @@ -1145,14 +1127,13 @@ mag_rteparse(char* rtemsg) QUEUE_FOR_EACH(&mag_rte_head->Q, elem, tmp) { mag_rte_elem* re = (mag_rte_elem*) elem; - Waypoint* waypt; queue* welem, *wtmp; /* * Copy route points from temp wpt queue. */ QUEUE_FOR_EACH(&rte_wpt_tmp, welem, wtmp) { - waypt = (Waypoint*)welem; + Waypoint* waypt = (Waypoint*)welem; if (waypt->shortname == re->wpt_name) { Waypoint* wpt = new Waypoint(*waypt); route_add_wpt(rte_head, wpt); @@ -1218,22 +1199,19 @@ mag_wptparse(char* trkmsg) char shortname[100]; char descr[256]; char icon_token[100]; - Waypoint* waypt; - char* icons; - char* icone; int i = 0; descr[0] = 0; icon_token[0] = 0; - waypt = new Waypoint; + Waypoint* waypt = new Waypoint; sscanf(trkmsg,"$PMGNWPL,%lf,%c,%lf,%c,%d,%c,%[^,],%[^,]", &latdeg,&latdir, &lngdeg,&lngdir, &alt,&altunits,shortname,descr); - icone = strrchr(trkmsg, '*'); - icons = strrchr(trkmsg, ',')+1; + char* icone = strrchr(trkmsg, '*'); + char* icons = strrchr(trkmsg, ',')+1; mag_dequote(descr); @@ -1348,21 +1326,18 @@ static void mag_waypt_pr(const Waypoint* waypointp) { - double lon, lat; - double ilon, ilat; - int lon_deg, lat_deg; char obuf[200]; char ofmtdesc[200]; QString icon_token; - ilat = waypointp->latitude; - ilon = waypointp->longitude; + double ilat = waypointp->latitude; + double ilon = waypointp->longitude; - lon = fabs(ilon); - lat = fabs(ilat); + double lon = fabs(ilon); + double lat = fabs(ilat); - lon_deg = lon; - lat_deg = lat; + int lon_deg = lon; + int lat_deg = lat; lon = (lon - lon_deg) * 60.0; lat = (lat - lat_deg) * 60.0; @@ -1431,16 +1406,13 @@ void mag_track_nop(const route_head*) static void mag_track_disp(const Waypoint* waypointp) { - double ilon, ilat; - double lon, lat; - int lon_deg, lat_deg; char obuf[200]; int hms=0; int fracsec=0; int date=0; - ilat = waypointp->latitude; - ilon = waypointp->longitude; + double ilat = waypointp->latitude; + double ilon = waypointp->longitude; struct tm* tm = nullptr; if (waypointp->creation_time.isValid()) { const time_t ct = waypointp->GetCreationTime().toTime_t(); @@ -1458,11 +1430,11 @@ void mag_track_disp(const Waypoint* waypointp) fracsec = 0; } - lon = fabs(ilon); - lat = fabs(ilat); + double lon = fabs(ilon); + double lat = fabs(ilat); - lon_deg = lon; - lat_deg = lat; + int lon_deg = lon; + int lat_deg = lat; lon = (lon - lon_deg) * 60.0; lat = (lat - lat_deg) * 60.0; @@ -1502,25 +1474,23 @@ static void mag_route_trl(const route_head* rte) { queue* elem, *tmp; - Waypoint* waypointp; char obuff[256]; char buff1[64], buff2[64]; char* pbuff; QString icon_token; - int i, numlines, thisline; /* count waypoints for this route */ - i = rte->rte_waypt_ct; + int i = rte->rte_waypt_ct; /* number of output PMGNRTE messages at 2 points per line */ - numlines = (i / 2) + (i % 2); + int numlines = (i / 2) + (i % 2); /* increment the route counter. */ route_out_count++; - thisline = i = 0; + int thisline = i = 0; QUEUE_FOR_EACH(&rte->waypoint_list, elem, tmp) { - waypointp = (Waypoint*) elem; + Waypoint* waypointp = (Waypoint*) elem; i++; if (deficon) { diff --git a/main.cc b/main.cc index d466fc23d..3776e31fb 100644 --- a/main.cc +++ b/main.cc @@ -695,9 +695,7 @@ main(int argc, char* argv[]) tracking_status.request_terminate = 0; while (!tracking_status.request_terminate) { - Waypoint* wpt; - - wpt = ivecs->position_ops.rd_position(&tracking_status); + Waypoint* wpt = ivecs->position_ops.rd_position(&tracking_status); if (tracking_status.request_terminate) { delete wpt; diff --git a/mapasia.cc b/mapasia.cc index b2cff6a18..c6b370eb6 100644 --- a/mapasia.cc +++ b/mapasia.cc @@ -70,24 +70,20 @@ static void tr7_read() { route_head* trk = nullptr; - unsigned int magic; Waypoint* prev = nullptr; - magic = gbfgetint32(fin); + unsigned int magic = gbfgetint32(fin); if (magic != TR7_TRACK_MAGIC) { fatal(MYNAME ": Invalid magic number in header (%X, but %X expected)!\n", magic, TR7_TRACK_MAGIC); } while (! gbfeof(fin)) { unsigned char buff[TR7_S_SIZE]; - double lat, lon; - Waypoint* wpt; - float speed, course; gbfread(buff, 1, sizeof(buff), fin); - lat = (double)le_read32(&buff[TR7_S_LAT]) / 1000000.0; - lon = (double)le_read32(&buff[TR7_S_LON]) / 1000000.0; + double lat = (double)le_read32(&buff[TR7_S_LAT]) / 1000000.0; + double lon = (double)le_read32(&buff[TR7_S_LON]) / 1000000.0; if ((fabs(lat) > 90) || (fabs(lon) > 180)) { /* that really happens */ trk = nullptr; @@ -104,13 +100,13 @@ tr7_read() continue; } - speed = KPH_TO_MPS(le_read16(&buff[TR7_S_SPEED])); - course = 360 - le_read16(&buff[TR7_S_COURSE]); + float speed = KPH_TO_MPS(le_read16(&buff[TR7_S_SPEED])); + float course = 360 - le_read16(&buff[TR7_S_COURSE]); if ((speed < 0) || (course > 360) || (course < 0)) { continue; } - wpt = new Waypoint; + Waypoint* wpt = new Waypoint; wpt->latitude = lat; wpt->longitude = lon; diff --git a/mapsend.cc b/mapsend.cc index 3827daf90..262a2c91a 100644 --- a/mapsend.cc +++ b/mapsend.cc @@ -108,11 +108,10 @@ static void mapsend_wpt_read() { char tbuf[256]; - int wpt_count, rte_count, rte_num; char wpt_icon; Waypoint* wpt_tmp; - wpt_count = gbfgetint32(mapsend_file_in); + int wpt_count = gbfgetint32(mapsend_file_in); while (wpt_count--) { wpt_tmp = new Waypoint; @@ -141,7 +140,7 @@ mapsend_wpt_read() } /* now read the routes... */ - rte_count = gbfgetint32(mapsend_file_in); + int rte_count = gbfgetint32(mapsend_file_in); while (rte_count--) { route_head* rte_head = route_head_alloc(); @@ -151,7 +150,7 @@ mapsend_wpt_read() rte_head->rte_name = gbfgetpstr(mapsend_file_in); /* route # */ - rte_num = gbfgetint32(mapsend_file_in); + int rte_num = gbfgetint32(mapsend_file_in); rte_head->rte_num = rte_num; /* points this route */ @@ -186,14 +185,11 @@ mapsend_wpt_read() static void mapsend_track_read() { - unsigned int trk_count; - route_head* track_head; - - track_head = route_head_alloc(); + route_head* track_head = route_head_alloc(); track_head->rte_name = gbfgetpstr(mapsend_file_in); track_add_head(track_head); - trk_count = gbfgetuint32(mapsend_file_in); + unsigned int trk_count = gbfgetuint32(mapsend_file_in); while (trk_count--) { Waypoint* wpt_tmp = new Waypoint; @@ -230,8 +226,6 @@ static void mapsend_read() { mapsend_hdr hdr; - int type; - gbsize_t len; char buf[3]; /* @@ -239,10 +233,10 @@ mapsend_read() * strings, each member has to be read in one at a time. Grrr. */ - len = gbfread(&hdr, 1, sizeof(hdr), mapsend_file_in); + gbsize_t len = gbfread(&hdr, 1, sizeof(hdr), mapsend_file_in); is_fatal(len < sizeof(hdr), MYNAME ": No mapsend or empty file!"); - type = le_read16(&hdr.ms_type); + int type = le_read16(&hdr.ms_type); strncpy(buf, hdr.ms_version, 2); buf[2] = '\0'; @@ -268,7 +262,6 @@ mapsend_read() static void mapsend_waypt_pr(const Waypoint* waypointp) { - double falt; static int cnt = 0; QString sn = global_opts.synthesize_shortnames ? mkshort_from_wpt(mkshort_handle, waypointp) : @@ -329,7 +322,7 @@ mapsend_waypt_pr(const Waypoint* waypointp) gbfputc(c, mapsend_file_out); gbfputc(1, mapsend_file_out); - falt = waypointp->altitude; + double falt = waypointp->altitude; if (falt == unknown_alt) { falt = 0; } @@ -370,7 +363,6 @@ static void mapsend_route_disp(const Waypoint* waypointp) { unsigned char c; - QString iconp; route_wp_count++; @@ -384,7 +376,7 @@ mapsend_route_disp(const Waypoint* waypointp) gbfputdbl(-waypointp->latitude, mapsend_file_out); if (!waypointp->icon_descr.isNull()) { - iconp = mag_find_token_from_descr(waypointp->icon_descr); + QString iconp = mag_find_token_from_descr(waypointp->icon_descr); if (1 == iconp.size()) { c = iconp[0].toLatin1() - 'a'; } else { @@ -404,7 +396,6 @@ static void mapsend_track_hdr(const route_head* trk) */ const char* verstring = "30"; queue* elem, *tmp; - int i; mapsend_hdr hdr = {13, {'4','D','5','3','3','3','3','4',' ','M','S'}, {'3','0'}, ms_type_track, {0, 0, 0} }; @@ -437,7 +428,7 @@ static void mapsend_track_hdr(const route_head* trk) gbfputpstr(tname, mapsend_file_out); /* total nodes (waypoints) this track */ - i = 0; + int i = 0; QUEUE_FOR_EACH(&trk->waypoint_list, elem, tmp) { i++; } @@ -449,7 +440,6 @@ static void mapsend_track_hdr(const route_head* trk) static void mapsend_track_disp(const Waypoint* wpt) { unsigned char c; - int32_t t; static int last_time; /* @@ -462,7 +452,7 @@ static void mapsend_track_disp(const Waypoint* wpt) * * This is rumoured (but yet unconfirmed) to be fixed in f/w 5.12. */ - t = wpt->GetCreationTime().toTime_t(); + int32_t t = wpt->GetCreationTime().toTime_t(); if (t < last_time) { t = last_time; } diff --git a/mapsource.cc b/mapsource.cc index 3c8b5a4af..190deb78b 100644 --- a/mapsource.cc +++ b/mapsource.cc @@ -330,14 +330,13 @@ static void mps_fileHeader_r(gbfile* mps_file, int* mps_ver) { char hdr[100]; - int reclen; mps_readstr(mps_file, hdr, sizeof(hdr)); if (strcmp(hdr, "MsRcd")) { fatal(MYNAME ": This doesn't look like a mapsource file.\n"); } /* Read record length of "format details" section */ - reclen = gbfgetint32(mps_file); + int reclen = gbfgetint32(mps_file); /* Read the "format details" in plus the trailing null */ gbfread(hdr, 3, 1, mps_file); if (hdr[0] != 'D') { @@ -371,7 +370,6 @@ static void mps_fileHeader_w(gbfile* mps_file, int mps_ver) { char hdr[100]; - int reclen; strcpy(hdr, "MsRc"); gbfwrite(hdr, 4, 1, mps_file); @@ -392,7 +390,7 @@ mps_fileHeader_w(gbfile* mps_file, int mps_ver) } hdr[2] = 0; - reclen = 2; /* this is 3 byte record */ + int reclen = 2; /* this is 3 byte record */ gbfputint32(reclen, mps_file); gbfwrite(hdr, 3, 1, mps_file); /* reclen + 1 */ @@ -466,8 +464,6 @@ mps_mapsegment_r(gbfile* mps_file, int mps_ver) static void mps_mapsetname_r(gbfile* mps_file, int mps_ver) { - int reclen; - (void)mps_ver; /* At the moment we're not doing anything with mapsetnames, but here's the template code as if we were @@ -479,7 +475,7 @@ mps_mapsetname_r(gbfile* mps_file, int mps_ver) gbfread(&mapsetnameAutonameFlag, 1, 1, mps_file); */ gbfseek(mps_file, -5, SEEK_CUR); - reclen = gbfgetint32(mps_file); + int reclen = gbfgetint32(mps_file); gbfseek(mps_file, reclen+1, SEEK_CUR); return; } @@ -494,14 +490,13 @@ static void mps_mapsetname_w(gbfile* mps_file, int mps_ver) { char hdr[100]; - int reclen; (void)mps_ver; hdr[0] = 'V'; /* mapsetname start of record indicator */ hdr[1] = 0; /* zero length null terminated string */ hdr[2] = 1; /* mapsetname autoname flag set to DO autoname */ - reclen = 2; /* three bytes of the V record */ + int reclen = 2; /* three bytes of the V record */ gbfputint32(reclen, mps_file); gbfwrite(hdr, 3, 1, mps_file); /* reclen + 1 */ } @@ -606,10 +601,6 @@ mps_waypoint_r(gbfile* mps_file, int mps_ver, Waypoint** wpt, unsigned int* mpsc static void mps_waypoint_w(gbfile* mps_file, int mps_ver, const Waypoint* wpt, const bool isRouteWpt) { - int reclen; - int lat, lon; - int icon; - char* ascii_description; char zbuf[25]; char ffbuf[25]; int display = 1; @@ -619,8 +610,8 @@ mps_waypoint_w(gbfile* mps_file, int mps_ver, const Waypoint* wpt, const bool is double mps_proximity = (mpsuseprox ? WAYPT_GET(wpt, proximity, unknown_alt) : unknown_alt); double mps_depth = unknown_alt; - lat = GPS_Math_Deg_To_Semi(wpt->latitude); - lon = GPS_Math_Deg_To_Semi(wpt->longitude); + int lat = GPS_Math_Deg_To_Semi(wpt->latitude); + int lon = GPS_Math_Deg_To_Semi(wpt->longitude); if (WAYPT_HAS(wpt, depth) && mpsusedepth) { mps_depth = wpt->depth; } @@ -639,7 +630,7 @@ mps_waypoint_w(gbfile* mps_file, int mps_ver, const Waypoint* wpt, const bool is memset(ffbuf, 0xff, sizeof(ffbuf)); /* might need to change this to handle version dependent icon handling */ - icon = gt_find_icon_number_from_desc(wpt->icon_descr, MAPSOURCE); + int icon = gt_find_icon_number_from_desc(wpt->icon_descr, MAPSOURCE); if (get_cache_icon(wpt)) { icon = gt_find_icon_number_from_desc(get_cache_icon(wpt), MAPSOURCE); } @@ -647,8 +638,8 @@ mps_waypoint_w(gbfile* mps_file, int mps_ver, const Waypoint* wpt, const bool is icon = mps_converted_icon_number(icon, mps_ver, MAPSOURCE); /* two NULL (0x0) bytes at end of each string */ - ascii_description = xstrdup(wpt->description); - reclen = ident.length() + strlen(ascii_description) + 2; + char* ascii_description = xstrdup(wpt->description); + int reclen = ident.length() + strlen(ascii_description) + 2; if ((mps_ver == 4) || (mps_ver == 5)) { /* v4.06 & V5.0*/ reclen += 85; /* "W" (1) + strlen(name) + NULL (1) + class(4) + country(sz) + @@ -865,7 +856,6 @@ mps_route_r(gbfile* mps_file, int mps_ver, route_head** rte) int lon = 0; char rte_autoname; int interlinkStepCount; - int thisInterlinkStep; unsigned int mpsclass; route_head* rte_head; @@ -1015,7 +1005,7 @@ mps_route_r(gbfile* mps_file, int mps_ver, route_head** rte) /* take two off the count since we separately read the start and end parts of the link */ /* MRCB 2004/09/15 - NOPE, sorry, this needs to one, since interlink steps can be > 0 */ - for (thisInterlinkStep = interlinkStepCount - 1; thisInterlinkStep > 0; thisInterlinkStep--) { + for (int thisInterlinkStep = interlinkStepCount - 1; thisInterlinkStep > 0; thisInterlinkStep--) { /* Could do this by doing a calculation on length of each co-ordinate and just doing one read but doing it this way makes it easier in the future to make use of this data */ lat = gbfgetint32(mps_file); @@ -1104,16 +1094,11 @@ mps_route_r(gbfile* mps_file, int mps_ver, route_head** rte) static void mps_routehdr_w(gbfile* mps_file, int mps_ver, const route_head* rte) { - unsigned int reclen; - unsigned int rte_datapoints; - int rname_len; char* rname; char hdr[20]; char zbuf[20]; - Waypoint* testwpt; time_t uniqueValue = 0; - int allWptNameLengths; double maxlat=-90.0; double maxlon=-180.0; @@ -1122,9 +1107,6 @@ mps_routehdr_w(gbfile* mps_file, int mps_ver, const route_head* rte) double maxalt=unknown_alt; double minalt=-unknown_alt; - int lat; - int lon; - queue* elem, *tmp; prevRouteWpt = nullptr; /* clear the stateful flag used to know when the start of route wpts happens */ @@ -1132,12 +1114,12 @@ mps_routehdr_w(gbfile* mps_file, int mps_ver, const route_head* rte) memset(zbuf, 0, sizeof(zbuf)); /* total nodes (waypoints) this route */ - rte_datapoints = 0; - allWptNameLengths = 0; + unsigned int rte_datapoints = 0; + int allWptNameLengths = 0; if (rte->waypoint_list.next) { /* this test doesn't do what I want i.e test if this is a valid route - treat as a placeholder for now */ QUEUE_FOR_EACH(&rte->waypoint_list, elem, tmp) { - testwpt = (Waypoint*)elem; + Waypoint* testwpt = (Waypoint*)elem; if (rte_datapoints == 0) { uniqueValue = testwpt->GetCreationTime().toTime_t(); } @@ -1191,8 +1173,8 @@ mps_routehdr_w(gbfile* mps_file, int mps_ver, const route_head* rte) rname = xstrdup(rte->rte_name); } - rname_len = strlen(rname); - reclen = rname_len + 42; /* "T" (1) + strlen(tname) + NULL (1) + autoname flag (2) + + int rname_len = strlen(rname); + unsigned int reclen = rname_len + 42; /* "T" (1) + strlen(tname) + NULL (1) + autoname flag (2) + route lat lon max (2x4) + route max alt (9) + route lat lon min (2x4) + route min alt (9) + num route datapoints value (4) */ @@ -1225,8 +1207,8 @@ mps_routehdr_w(gbfile* mps_file, int mps_ver, const route_head* rte) hdr[2] = 0; /* MSB of don't autoname */ gbfwrite(hdr, 3, 1, mps_file); /* NULL string terminator + route autoname flag */ - lat = GPS_Math_Deg_To_Semi(maxlat); - lon = GPS_Math_Deg_To_Semi(maxlon); + int lat = GPS_Math_Deg_To_Semi(maxlat); + int lon = GPS_Math_Deg_To_Semi(maxlon); gbfputint32(lat, mps_file); gbfputint32(lon, mps_file); @@ -1269,11 +1251,8 @@ mps_routehdr_w_wrapper(const route_head* rte) static void mps_routedatapoint_w(gbfile* mps_file, int mps_ver, const Waypoint* rtewpt) { - int lat; - int lon; char zbuf[20]; char ffbuf[20]; - int reclen; int maxlat; int maxlon; @@ -1282,25 +1261,22 @@ mps_routedatapoint_w(gbfile* mps_file, int mps_ver, const Waypoint* rtewpt) double maxalt=unknown_alt; double minalt=-unknown_alt; - double mps_altitude; - Waypoint* wptfound; - memset(zbuf, 0, sizeof(zbuf)); memset(ffbuf, 0xff, sizeof(ffbuf)); if (prevRouteWpt != nullptr) { /* output the route link details */ - reclen = 2; + int reclen = 2; gbfputint32(reclen, mps_file); /* output end point 1 */ - lat = GPS_Math_Deg_To_Semi(prevRouteWpt->latitude); - lon = GPS_Math_Deg_To_Semi(prevRouteWpt->longitude); + int lat = GPS_Math_Deg_To_Semi(prevRouteWpt->latitude); + int lon = GPS_Math_Deg_To_Semi(prevRouteWpt->longitude); gbfputint32(lat, mps_file); gbfputint32(lon, mps_file); - mps_altitude = prevRouteWpt->altitude; + double mps_altitude = prevRouteWpt->altitude; if (mps_altitude == unknown_alt) { gbfwrite(zbuf, 9, 1, mps_file); } else { @@ -1396,7 +1372,7 @@ mps_routedatapoint_w(gbfile* mps_file, int mps_ver, const Waypoint* rtewpt) gbfputs(ident, mps_file); gbfwrite(zbuf, 1, 1, mps_file); /* NULL termination to ident */ - wptfound = mps_find_wpt_q_by_name(&written_route_wpt_head, ident); + Waypoint* wptfound = mps_find_wpt_q_by_name(&written_route_wpt_head, ident); if (wptfound != nullptr) { zbuf[0] = (char)MPSHIDDENROUTEWPTCLASS; } else { @@ -1557,13 +1533,9 @@ mps_track_r(gbfile* mps_file, int mps_ver, route_head** trk) static void mps_trackhdr_w(gbfile* mps_file, int mps_ver, const route_head* trk) { - unsigned int reclen; - unsigned int trk_datapoints; unsigned int colour = 0; /* unknown colour */ - int tname_len; char* tname; char hdr[20]; - Waypoint* testwpt; time_t uniqueValue = 0; queue* elem, *tmp; @@ -1571,11 +1543,11 @@ mps_trackhdr_w(gbfile* mps_file, int mps_ver, const route_head* trk) (void)mps_ver; /* total nodes (waypoints) this track */ - trk_datapoints = 0; + unsigned int trk_datapoints = 0; if (trk->waypoint_list.next) { /* this test doesn't do what I want i.e test if this is a valid track - treat as a placeholder for now */ QUEUE_FOR_EACH(&trk->waypoint_list, elem, tmp) { if (trk_datapoints == 0) { - testwpt = (Waypoint*)elem; + Waypoint* testwpt = (Waypoint*)elem; uniqueValue = testwpt->GetCreationTime().toTime_t(); } trk_datapoints++; @@ -1593,8 +1565,8 @@ mps_trackhdr_w(gbfile* mps_file, int mps_ver, const route_head* trk) tname = xstrdup(trk->rte_name); } - tname_len = strlen(tname); - reclen = tname_len + 11; /* "T" (1) + strlen(tname) + NULL (1) + display flag (1) + colour (4) + + int tname_len = strlen(tname); + unsigned int reclen = tname_len + 11; /* "T" (1) + strlen(tname) + NULL (1) + display flag (1) + colour (4) + num track datapoints value (4) */ reclen += (trk_datapoints * 31) - 1; /* lat (4) + lon (4) + alt (9) + date (5) + depth (9) ;*/ @@ -1805,7 +1777,6 @@ mps_read() static void mps_write() { - int short_length; Waypoint* wpt; route_head* rte; route_head* trk; @@ -1817,12 +1788,11 @@ mps_write() unsigned int tocopy; unsigned int block; - long tempFilePos; unsigned int mpsWptClass; unsigned char copybuf[8192]; - short_length = atoi(snlen); + int short_length = atoi(snlen); if (mpsmergeout) { /* need to skip over the merging header and test merge version */ @@ -1880,7 +1850,7 @@ mps_write() gbfwrite(&reclen, 4, 1, mps_file_out); /* write out untouched */ gbfwrite(&recType, 1, 1, mps_file_out); - tempFilePos = gbftell(mps_file_temp); + long tempFilePos = gbftell(mps_file_temp); /* need to read in the waypoint info only because later we may need to check for uniqueness since we're here because the user didn't request waypoints, this should be acceptable */ mps_waypoint_r(mps_file_temp, mps_ver_temp, &wpt, &mpsWptClass); diff --git a/mkshort.cc b/mkshort.cc index be4cd9f67..773770ee3 100644 --- a/mkshort.cc +++ b/mkshort.cc @@ -108,9 +108,8 @@ uniq_shortname* is_unique(mkshort_handle_imp* h, char* name) { queue* e, *t; - int hash; - hash = hash_string(name); + int hash = hash_string(name); QUEUE_FOR_EACH(&h->namelist[hash], e, t) { uniq_shortname* z = (uniq_shortname*) e; if (0 == case_ignore_strcmp(z->orig_shortname, name)) { @@ -137,13 +136,12 @@ mkshort_add_to_list(mkshort_handle_imp* h, char* name) uniq_shortname* s; while ((s = is_unique(h, name))) { - int dl; char tbuf[10]; size_t l = strlen(name); s->conflictctr++; - dl = sprintf(tbuf, ".%d", s->conflictctr); + int dl = sprintf(tbuf, ".%d", s->conflictctr); if (l + dl < h->target_len) { name = (char*) xrealloc(name, l + dl + 1); @@ -208,12 +206,11 @@ delete_last_vowel(int start, char* istring, int* replaced) *replaced = 0; for (int l = strlen(istring); l > start; l--) { if (strchr(vowels, istring[l-1])) { - char* ostring; /* If vowel is the first letter of a word, keep it.*/ if (istring[l-2] == ' ') { continue; } - ostring = xstrdup(istring); + char* ostring = xstrdup(istring); strncpy(&ostring[l-1], &istring[l], 1+strlen(istring)-l); ostring[strlen(istring)-1] = 0; *replaced = 1; @@ -232,10 +229,9 @@ delete_last_vowel(int start, char* istring, int* replaced) void replace_constants(char* s) { - struct replacements* r; int origslen = strlen(s); - for (r = replacements; r->orig; r++) { + for (struct replacements* r = replacements; r->orig; r++) { int rl = strlen(r->orig); /* * If word is in replacement list and preceeded by a @@ -381,12 +377,9 @@ mkshort(short_handle h, const char* istring) #endif { char* ostring; - char* nstring; char* tstring; char* cp; - char* np; int i, l, replaced; - size_t nlen; mkshort_handle_imp* hdl = (mkshort_handle_imp*) h; if (hdl->is_utf8) { @@ -413,7 +406,7 @@ mkshort(short_handle h, const char* istring) if ((strlen(ostring) > hdl->target_len + 4) && (strncmp(ostring, "The ", 4) == 0 || strncmp(ostring, "the ", 4) == 0)) { - nstring = xxstrdup(ostring + 4, file, line); + char* nstring = xxstrdup(ostring + 4, file, line); xfree(ostring); ostring = nstring; } @@ -526,11 +519,11 @@ mkshort(short_handle h, const char* istring) * Walk in the Woods 2. */ - np = ostring + strlen(ostring); + char* np = ostring + strlen(ostring); while ((np != ostring) && *(np-1) && isdigit(*(np-1))) { np--; } - nlen = strlen(np); + size_t nlen = strlen(np); /* * Now brutally truncate the resulting string, preserve trailing diff --git a/mmo.cc b/mmo.cc index 44008c6c2..b615a6e4d 100644 --- a/mmo.cc +++ b/mmo.cc @@ -152,9 +152,8 @@ static char* mmo_readstr() { char* res; - signed int len; - len = (unsigned)gbfgetc(fin); + signed int len = (unsigned)gbfgetc(fin); if (len == 0xFF) { // Next two bytes are either the length (strings longer than 254 chars) // or FE then FF (which is -2) meaning a UTF-16 string @@ -168,10 +167,9 @@ mmo_readstr() res = (char*) xmalloc(len*2 + 1); // bigger to allow for utf-8 expansion for (signed int ii = 0; ii (unsigned int)bufsz) { fatal(MYNAME ": Internal error (bufsz too small)!\n"); } memset(buf, 0xFF, count); - res = gbfread(buf, 1, count, fin); + gbsize_t res = gbfread(buf, 1, count, fin); if (need_all && (res < count)) { fatal(MYNAME ": Unexpected end of file!\n"); } @@ -247,9 +243,7 @@ mmo_printbuf(const char* buf, int count, const char* comment) static mmo_data_t* mmo_register_object(const int objid, const void* ptr, const gpsdata_type type) { - mmo_data_t* data; - - data = (mmo_data_t*) xcalloc(1, sizeof(*data)); + mmo_data_t* data = (mmo_data_t*) xcalloc(1, sizeof(*data)); data->data = const_cast(ptr); data->visible = 1; data->locked = 0; @@ -277,9 +271,7 @@ mmo_get_objid(const void* ptr) static mmo_data_t* mmo_get_object(const uint16_t objid) { - int key; - - key = objid | 0x8000; + int key = objid | 0x8000; if (!objects.contains(key)) { #ifdef MMO_DBG gbfseek(fin, -2, SEEK_CUR); @@ -364,11 +356,9 @@ mmo_read_category(mmo_data_t* data) int marker = gbfgetuint16(fin); if (marker & 0x8000) { - mmo_data_t* tmp; - DBG(("mmo_read_category", "reading category object\n")); gbfseek(fin, -2, SEEK_CUR); - tmp = mmo_read_object(); + mmo_data_t* tmp = mmo_read_object(); if (data) { data->category = tmp->name; } @@ -409,10 +399,9 @@ mmo_read_CObjIcons(mmo_data_t* data) DBG((sobj, "unknown value = 0x%04X\n", u16)); while ((icon_id = gbfgetuint32(fin))) { - char* name; (void) gbfgetuint32(fin); (void) gbfgetuint32(fin); - name = mmo_readstr(); + char* name = mmo_readstr(); DBG((sobj, "bitmap(0x%08X) = \"%s\"\n", icon_id, name)); mmo_register_icon(icon_id, name); xfree(name); @@ -430,12 +419,9 @@ mmo_read_CObjWaypoint(mmo_data_t* data) const char* sobj = "CObjWaypoint"; #endif Waypoint* wpt; - time_t time; - int rtelinks; mmo_data_t** rtelink = nullptr; - char* str; char buf[16]; - int i, ux; + int i; DBG((sobj, ":-----------------------------------------------------\n")); DBG((sobj, "name = \"%s\" [ visible=%s, id=0x%04X ]\n", @@ -444,7 +430,7 @@ mmo_read_CObjWaypoint(mmo_data_t* data) data->data = wpt = new Waypoint; wpt->shortname = QString::fromLatin1(data->name); - time = data->mtime; + time_t time = data->mtime; if (! time) { time = data->ctime; } @@ -453,8 +439,7 @@ mmo_read_CObjWaypoint(mmo_data_t* data) } if (mmo_version >= 0x18) { - uint16_t u16; - u16 = gbfgetuint16(fin); + uint16_t u16 = gbfgetuint16(fin); DBG((sobj, "unknown value = 0x%04X (since 0x18)\n", u16)); u16 = gbfgetuint16(fin); DBG((sobj, "unknown value = 0x%04X (since 0x18)\n", u16)); @@ -470,7 +455,7 @@ mmo_read_CObjWaypoint(mmo_data_t* data) DBG((sobj, "trackpoint %d/%d coordinates = %f / %f\n", ctp+1,tp, wpt->latitude, wpt->longitude)); - rtelinks = gbfgetuint16(fin); + int rtelinks = gbfgetuint16(fin); if (rtelinks > 0) { rtelink = (mmo_data_t**) xcalloc(sizeof(*rtelink), rtelinks); @@ -483,12 +468,10 @@ mmo_read_CObjWaypoint(mmo_data_t* data) } - str = mmo_readstr(); /* descr + url */ + char* str = mmo_readstr(); /* descr + url */ if (strncmp(str, "_FILE_ ", 7) == 0) { - char* cx, *cend; - - cx = lrtrim(str + 7); - cend = strchr(cx, '\n'); + char* cx = lrtrim(str + 7); + char* cend = strchr(cx, '\n'); if (cend == nullptr) { cend = cx + strlen(cx); } @@ -544,7 +527,7 @@ mmo_read_CObjWaypoint(mmo_data_t* data) xfree(str); } - ux = gbfgetuint32(fin); + int ux = gbfgetuint32(fin); DBG((sobj, "proximity type = %d\n", ux)); (void) ux; @@ -565,7 +548,6 @@ mmo_read_CObjRoute(mmo_data_t* data) const char* sobj = "CObjRoute"; #endif route_head* rte; - int ux; DBG((sobj, ":-----------------------------------------------------\n")); DBG((sobj, "name = \"%s\" [ visible=%s, id=0x%04X ]\n", @@ -576,8 +558,7 @@ mmo_read_CObjRoute(mmo_data_t* data) route_add_head(rte); if (mmo_version >= 0x18) { - uint16_t u16; - u16 = gbfgetuint16(fin); + uint16_t u16 = gbfgetuint16(fin); DBG((sobj, "unknown value = 0x%04X (since 0x18)\n", u16)); u16 = gbfgetuint16(fin); DBG((sobj, "unknown value = 0x%04X (since 0x18)\n", u16)); @@ -588,7 +569,7 @@ mmo_read_CObjRoute(mmo_data_t* data) (void) u16; } - ux = gbfgetc(fin); /* line label */ + int ux = gbfgetc(fin); /* line label */ DBG((sobj, "line label = %d\n", ux)); (void) ux; @@ -606,10 +587,8 @@ mmo_read_CObjRoute(mmo_data_t* data) } while (data->left > 0) { - mmo_data_t* tmp; - DBG((sobj, "read next waypoint\n")); - tmp = mmo_read_object(); + mmo_data_t* tmp = mmo_read_object(); if (tmp && tmp->data && (tmp->type == wptdata)) { Waypoint* wpt; @@ -641,20 +620,17 @@ mmo_read_CObjTrack(mmo_data_t* data) #ifdef MMO_DBG const char* sobj = "CObjTrack"; #endif - int tp; - route_head* trk; DBG((sobj, ":-----------------------------------------------------\n")); DBG((sobj, "name = \"%s\" [ visible=%s, id=0x%04X ]\n", data->name, data->visible ? "yes" : "NO", data->objid)); - trk = route_head_alloc(); + route_head* trk = route_head_alloc(); trk->rte_name = data->name; track_add_head(trk); if (mmo_version >= 0x18) { - uint16_t u16; - u16 = gbfgetuint16(fin); + uint16_t u16 = gbfgetuint16(fin); DBG((sobj, "unknown value = 0x%04X (since 0x18)\n", u16)); u16 = gbfgetuint16(fin); DBG((sobj, "unknown value = 0x%04X (since 0x18)\n", u16)); @@ -665,27 +641,23 @@ mmo_read_CObjTrack(mmo_data_t* data) (void) u16; } - tp = gbfgetint16(fin); + int tp = gbfgetint16(fin); DBG((sobj, "track has %d point(s)\n", tp)); for (int ctp = 0; ctp < tp; ctp++) { - Waypoint* wpt; - char unk; - - wpt = new Waypoint; + Waypoint* wpt = new Waypoint; wpt->latitude = gbfgetdbl(fin); wpt->longitude = gbfgetdbl(fin); DBG((sobj, "coordinates = %f / %f\n", wpt->latitude, wpt->longitude)); - unk = gbfgetc(fin); + char unk = gbfgetc(fin); DBG((sobj, "Unknown = 0x%02X (%d)\n", unk, unk)); wpt->SetCreationTime(gbfgetint32(fin)); wpt->altitude = gbfgetflt(fin); if (unk != 0) { - uint16_t ux; - ux = gbfgetuint16(fin); + uint16_t ux = gbfgetuint16(fin); DBG((sobj, "unknown value = 0x%04X (%d)\n", ux, ux)); (void) ux; if (unk > 1) { @@ -699,9 +671,7 @@ mmo_read_CObjTrack(mmo_data_t* data) } if (mmo_version > 0) { - uint32_t u32; - - u32 = gbfgetuint32(fin); /* Min. update interval */ + uint32_t u32 = gbfgetuint32(fin); /* Min. update interval */ DBG((sobj, "min. update interval = %d\n", u32)); u32 = gbfgetuint32(fin); /* unknown */ DBG((sobj, "unknown value = 0x%08X (%d)\n", u32, u32)); @@ -722,9 +692,7 @@ mmo_read_CObjTrack(mmo_data_t* data) } if (mmo_version >= 0x12) { - char u8; - - u8 = gbfgetc(fin); + char u8 = gbfgetc(fin); DBG((sobj, "line width = %d - (since 0x12)\n", u8)); u8 = gbfgetc(fin); DBG((sobj, "line style = %d - (since 0x12)\n", u8)); @@ -733,14 +701,11 @@ mmo_read_CObjTrack(mmo_data_t* data) trk->line_color.opacity = 255 - (u8 * 51); if (mmo_version >= 0x16) { - uint16_t u16; - char* text; - // XXX ARB was u8 = gbfgetc(fin); but actually a string - text = mmo_readstr(); + char* text = mmo_readstr(); DBG((sobj, "text = \"%s\"\n", text)); xfree(text); - u16 = gbfgetuint16(fin); + uint16_t u16 = gbfgetuint16(fin); DBG((sobj, "unknown value = 0x%04X (since 0x16)\n", u16)); u16 = gbfgetuint16(fin); DBG((sobj, "unknown value = 0x%04X (since 0x16)\n", u16)); @@ -762,26 +727,24 @@ mmo_read_CObjText(mmo_data_t*) const char* sobj = "CObjText"; #endif char buf[28]; - double lat, lon; - char* text, *font; DBG((sobj, ":-----------------------------------------------------\n")); DBG((sobj, "name = \"%s\" [ visible=%s, id=0x%04X ]\n", data->name, data->visible ? "yes" : "NO", data->objid)); - lat = gbfgetdbl(fin); - lon = gbfgetdbl(fin); + double lat = gbfgetdbl(fin); + double lon = gbfgetdbl(fin); DBG((sobj, "coordinates = %f / %f\n", lat, lon)); (void) lat; (void) lon; - text = mmo_readstr(); + char* text = mmo_readstr(); DBG((sobj, "text = \"%s\"\n", text)); xfree(text); mmo_fillbuf(buf, 28, 1); - font = mmo_readstr(); + char* font = mmo_readstr(); DBG((sobj, "font = \"%s\"\n", font)); xfree(font); @@ -796,14 +759,13 @@ mmo_read_CObjCurrentPosition(mmo_data_t*) const char* sobj = "CObjCurrentPosition"; #endif char buf[24]; - double lat, lon; DBG((sobj, ":-----------------------------------------------------\n")); DBG((sobj, "name = \"%s\" [ visible=%s, id=0x%04X ]\n", data->name, data->visible ? "yes" : "NO", data->objid)); - lat = gbfgetdbl(fin); - lon = gbfgetdbl(fin); + double lat = gbfgetdbl(fin); + double lon = gbfgetdbl(fin); DBG((sobj, "coordinates = %f / %f\n", lat, lon)); (void) lat; (void) lon; @@ -814,9 +776,7 @@ mmo_read_CObjCurrentPosition(mmo_data_t*) } if (mmo_version >= 0x14) { - char* name; - - name = mmo_readstr(); + char* name = mmo_readstr(); DBG((sobj, "name = \"%s\"\n", name)); xfree(name); // XXX ARB was just: mmo_fillbuf(buf, 13, 1); @@ -834,7 +794,6 @@ mmo_read_CObjCurrentPosition(mmo_data_t*) static mmo_data_t* mmo_read_object() { - int objid; mmo_data_t* data = nullptr; // There are three cases: @@ -842,21 +801,18 @@ mmo_read_object() // a new object; or // a back reference to an object that appears earlier in the file. - objid = gbfgetuint16(fin); + int objid = gbfgetuint16(fin); if (objid == 0xFFFF) { - uint16_t version; - char* sobj; - int len; DBG(("mmo_read_object", "Registering new object type\n")); objid = mmo_object_id++; - version = gbfgetuint16(fin); + uint16_t version = gbfgetuint16(fin); is_fatal(version != mmo_version, MYNAME ": Invalid version identifier!\n"); - len = gbfgetint16(fin); + int len = gbfgetint16(fin); - sobj = (char*) xmalloc(len + 1); + char* sobj = (char*) xmalloc(len + 1); sobj[len] = '\0'; gbfread(sobj, len, 1, fin); DBG(("mmo_read_object", "%s\n", sobj)); @@ -888,13 +844,12 @@ mmo_read_object() data->name = mmo_readstr(); if (objid != cat_object_id) { - uint32_t obj_type; data->ctime = gbfgetuint32(fin); data->mtime = gbfgetuint32(fin); data->locked = gbfgetc(fin); data->visible = gbfgetc(fin); - obj_type = gbfgetuint32(fin); + uint32_t obj_type = gbfgetuint32(fin); (void) obj_type; #ifdef MMO_DBG uint32_t expected_type = 0xFFFFFFFF; @@ -996,8 +951,6 @@ mmo_finalize_rtept_cb(const Waypoint* wptref) static void mmo_rd_init(const QString& fname) { - int i; - fin = gbfopen_le(fname, "rb", MYNAME); ico_object_id = pos_object_id = txt_object_id = cat_object_id = 0; @@ -1005,7 +958,7 @@ mmo_rd_init(const QString& fname) mmo_object_id = 0x8001; - i = 0; + int i = 0; while (mmo_icon_value_table[i].icon) { mmo_register_icon(mmo_icon_value_table[i].value, mmo_icon_value_table[i].icon); i++; @@ -1035,14 +988,12 @@ mmo_read() #ifdef MMO_DBG const char* sobj = "main"; #endif - gbfile* fx; - int i; /* copy file to memory stream (needed for seek-ops and piped commands) */ DBG(("main", "loading file \"%s\".\n", fin->name)); - fx = gbfopen(nullptr, "wb", MYNAME); + gbfile* fx = gbfopen(nullptr, "wb", MYNAME); gbfcopyfrom(fx, fin, 0x7FFFFFFF); gbfrewind(fx); gbfclose(fin); @@ -1051,7 +1002,7 @@ mmo_read() mmo_obj_ct = gbfgetuint16(fin); DBG((sobj, "number of objects = %d\n", mmo_obj_ct)); - i = gbfgetuint16(fin); + int i = gbfgetuint16(fin); if (i != 0xFFFF) { fatal(MYNAME ": Marker not equal to 0xFFFF!\n"); } @@ -1192,11 +1143,10 @@ mmo_write_obj_mark(const char* sobj, const char* name) static void mmo_write_category(const char* sobj, const char* name) { - uint16_t nr; QString key = QString::fromUtf8(name); if (category_names.contains(key)) { - nr = category_names.value(key); + uint16_t nr = category_names.value(key); gbfputuint16(nr & 0x7FFF, fout); } else { mmo_write_obj_mark(sobj, name); @@ -1209,9 +1159,7 @@ static int mmo_write_obj_head(const char* sobj, const char* name, const time_t ctime, const uint32_t obj_type) { - int res; - - res = mmo_write_obj_mark(sobj, name); + int res = mmo_write_obj_mark(sobj, name); gbfputuint32(ctime, fout); gbfputuint32(ctime, fout); @@ -1229,13 +1177,9 @@ static void mmo_write_wpt_cb(const Waypoint* wpt) { QString str; - QString cx; - int objid; - time_t time; int icon = 0; - mmo_data_t* data; - time = wpt->GetCreationTime().toTime_t(); + time_t time = wpt->GetCreationTime().toTime_t(); if (time < 0) { time = 0; } @@ -1255,9 +1199,9 @@ mmo_write_wpt_cb(const Waypoint* wpt) } DBG(("write", "waypoint \"%s\"\n", wpt->shortname ? wpt->shortname : "Mark")); - objid = mmo_write_obj_head("CObjWaypoint", - wpt->shortname.isEmpty() ? "Mark" : CSTRc(wpt->shortname), time, obj_type_wpt); - data = mmo_register_object(objid, wpt, wptdata); + int objid = mmo_write_obj_head("CObjWaypoint", + wpt->shortname.isEmpty() ? "Mark" : CSTRc(wpt->shortname), time, obj_type_wpt); + mmo_data_t* data = mmo_register_object(objid, wpt, wptdata); data->refct = 1; mmo_write_category("CCategory", (mmo_datatype == rtedata) ? "Waypoints" : "Marks"); @@ -1279,7 +1223,7 @@ mmo_write_wpt_cb(const Waypoint* wpt) str += "\n"; } - cx = wpt->notes; + QString cx = wpt->notes; if (cx == nullptr) { cx = wpt->description; } @@ -1325,7 +1269,6 @@ mmo_write_wpt_cb(const Waypoint* wpt) static void mmo_write_rte_head_cb(const route_head* rte) { - int objid; queue* elem, *tmp; time_t time = 0x7FFFFFFF; @@ -1345,8 +1288,8 @@ mmo_write_rte_head_cb(const route_head* rte) if (time == 0x7FFFFFFF) { time = gpsbabel_time; } - objid = mmo_write_obj_head("CObjRoute", - rte->rte_name.isEmpty() ? "Route" : CSTRc(rte->rte_name), time, obj_type_rte); + int objid = mmo_write_obj_head("CObjRoute", + rte->rte_name.isEmpty() ? "Route" : CSTRc(rte->rte_name), time, obj_type_rte); mmo_register_object(objid, rte, rtedata); mmo_write_category("CCategory", "Route"); gbfputc(0, fout); /* unknown */ @@ -1390,13 +1333,11 @@ mmo_write_rte_tail_cb(const route_head* rte) static void mmo_write_trk_head_cb(const route_head* trk) { - int objid; - if (trk->rte_waypt_ct <= 0) { return; } - objid = mmo_write_obj_head("CObjTrack", - trk->rte_name.isEmpty() ? "Track" : CSTRc(trk->rte_name), gpsbabel_time, obj_type_trk); + int objid = mmo_write_obj_head("CObjTrack", + trk->rte_name.isEmpty() ? "Track" : CSTRc(trk->rte_name), gpsbabel_time, obj_type_trk); mmo_write_category("CCategory", "Track"); gbfputuint16(trk->rte_waypt_ct, fout); diff --git a/mtk_locus.cc b/mtk_locus.cc index eb3b38ae5..f58dac73e 100644 --- a/mtk_locus.cc +++ b/mtk_locus.cc @@ -261,13 +261,10 @@ set_baudrate() void read_line() { - int rc; - char* s; - line[0] = '\0'; if (read_mode == rm_file) { - s = gbfgetstr(ffd); + char* s = gbfgetstr(ffd); if (s == nullptr) { dbg(1, "EOF reached\n"); download_complete = 1; @@ -275,7 +272,7 @@ read_line() } strncat(line, s, sizeof(line)-1); } else { - rc = gbser_read_line(sfd, line, sizeof(line)-1, TIMEOUT, 0x0A, 0x0D); + int rc = gbser_read_line(sfd, line, sizeof(line)-1, TIMEOUT, 0x0A, 0x0D); if (rc != gbser_OK) { fatal(MYNAME "Serial read failed: %i\n", rc); } @@ -289,8 +286,6 @@ read_line() void process_packet() { - - int calculated_checksum; int given_checksum; if ((strlen(line) < 3) || (line[0] != '$') || (line[strlen(line)-3] != '*')) { @@ -298,7 +293,7 @@ process_packet() return; } - calculated_checksum = calculate_checksum(&line[1], strlen(line) - 1 - 3); + int calculated_checksum = calculate_checksum(&line[1], strlen(line) - 1 - 3); sscanf(&line[strlen(line) - 2], "%02x", &given_checksum); if (calculated_checksum != given_checksum) { dbg(1, "Line %i: NMEA Checksum incorrect, expecting %02X\n", packetnum, calculated_checksum); @@ -331,30 +326,18 @@ process_packet() void process_pmtklox() { - - char* token; - char* loxtype; - int loxsequence; - uint32_t timestamp; - char fixtype; - float latitude; - float longitude; - int height; - uint8_t calculated_checksum; int hexval; uint8_t fixbytes[16]; - int bytenum; - int fixnum; static Waypoint* trkpt; static Waypoint* waypt; - token = strtok(line, ","); + char* token = strtok(line, ","); if ((token == nullptr) || (strcmp(token, "$PMTKLOX") != 0)) { warning("Line %i: Invalid packet id\n", packetnum); return; } - loxtype = strtok(nullptr, ","); + char* loxtype = strtok(nullptr, ","); if (loxtype == nullptr) { warning("Line %i: Missing lox type\n", packetnum); return; @@ -377,7 +360,7 @@ process_pmtklox() return; } - loxsequence = atoi(strtok(nullptr, ",")); + int loxsequence = atoi(strtok(nullptr, ",")); if (first_loxsequence == -1) { first_loxsequence = loxsequence; @@ -391,11 +374,11 @@ process_pmtklox() } token = strtok(nullptr, ","); - fixnum = 0; + int fixnum = 0; while (token != nullptr) { fixnum++; - bytenum = 0; - calculated_checksum = 0; + int bytenum = 0; + uint8_t calculated_checksum = 0; for (int wordnum = 0; wordnum<4; wordnum++) { // 4 8-byte hex strings per fix if (token == nullptr) { dbg(1, "Line %i: Fix %i incomplete data\n", packetnum, fixnum); @@ -414,11 +397,11 @@ process_pmtklox() continue; } - timestamp = le_read32(&fixbytes[0]); - fixtype = fixbytes[4]; - latitude = le_read_float(&fixbytes[5]); - longitude = le_read_float(&fixbytes[9]); - height = le_read16(&fixbytes[13]); + uint32_t timestamp = le_read32(&fixbytes[0]); + char fixtype = fixbytes[4]; + float latitude = le_read_float(&fixbytes[5]); + float longitude = le_read_float(&fixbytes[9]); + int height = le_read16(&fixbytes[13]); if (fixtype != '\x02') { dbg(1, "line %i: Fix %i Invalid fix type: %02X\n", packetnum, fixnum, fixtype); @@ -465,14 +448,11 @@ process_pmtklox() void process_pmtklog() { - int status; - int type; - strtok(line, ","); printf("Serial#: %s\n", strtok(nullptr, ",")); - type = atoi(strtok(nullptr, ",")); + int type = atoi(strtok(nullptr, ",")); if (type == 0) { printf("Type: %i (wrap around when full)\n", type); } else { @@ -485,7 +465,7 @@ process_pmtklog() printf("Distance: %s\n", strtok(nullptr, ",")); printf("Speed: %s\n", strtok(nullptr, ",")); - status = atoi(strtok(nullptr, ",")); + int status = atoi(strtok(nullptr, ",")); if (status == 0) { printf("Status: %i (enabled)\n", status); } else { @@ -499,12 +479,9 @@ process_pmtklog() void process_pmtk001() { - char* cmd; - char* flag; - strtok(line, ","); - cmd = strtok(nullptr,","); - flag = strtok(nullptr,","); + char* cmd = strtok(nullptr,","); + char* flag = strtok(nullptr,","); switch (atoi(flag)) { case 0: @@ -528,9 +505,7 @@ process_pmtk001() void process_pmtk705() { - char* token; - - token = strtok(line, ","); + char* token = strtok(line, ","); token = strtok(nullptr,","); printf("Firmware: %s\n", token); @@ -539,21 +514,19 @@ process_pmtk705() void send_command(const char* s, const char* wait_for) { - int rc; time_t starttime; time_t currtime; char cmd[100]; - int checksum; if (read_mode == rm_file) { dbg(1, "Sending device commands ignored when using file input: %s\n", s); return; } - checksum = calculate_checksum(&s[1], strlen(s)-1); + int checksum = calculate_checksum(&s[1], strlen(s)-1); snprintf(cmd, sizeof(cmd)-1, "%s*%02X\r\n", s, checksum); - rc = gbser_print(sfd, cmd); + int rc = gbser_print(sfd, cmd); if (rc != gbser_OK) { fatal(MYNAME ": Write error (%d)\n", rc); } @@ -586,8 +559,7 @@ send_command(const char* s, const char* wait_for) int calculate_checksum(const char* s, int length) { - int sum; - sum = 0; + int sum = 0; for (int i = 0; i 0) { @@ -356,12 +354,11 @@ static int do_cmd(const char* cmd, const char* expect, char** rslt, time_t timeo do_send_cmd(cmd, strlen(cmd)); // success or fatal()... - done = 0; - loops = 0; + int done = 0; + int loops = 0; memset(line, '\0', sizeof(line)); do { - int rc; - rc = gbser_read_line(fd, line, sizeof(line)-1, TIMEOUT, 0x0A, 0x0D); + int rc = gbser_read_line(fd, line, sizeof(line)-1, TIMEOUT, 0x0A, 0x0D); if (rc != gbser_OK) { if (rc == gbser_TIMEOUT && time(nullptr) > tout) { dbg(2, "NMEA command '%s' timeout !\n", cmd); @@ -399,9 +396,8 @@ static int do_cmd(const char* cmd, const char* expect, char** rslt, time_t timeo } else if (strncmp(line, "$PMTK", 5) == 0) { /* A quick parser for ACK packets */ if (!cmd_erase && strncmp(line, "$PMTK001,", 9) == 0 && line[9] != '\0') { - char* pType, *pRslt; - pType = &line[9]; - pRslt = strchr(&line[9], ',') + 1; + char* pType = &line[9]; + char* pRslt = strchr(&line[9], ',') + 1; if (memcmp(&cmd[5], pType, 3) == 0 && pRslt != nullptr && *pRslt != '\0') { int pAck = *pRslt - '0'; if (pAck != 3 && pAck >= 0 && pAck < 4) { // Erase will return '2' @@ -499,10 +495,9 @@ static void mtk_rd_deinit() static int mtk_erase() { - int log_status; char* lstatus = nullptr; - log_status = 0; + int log_status = 0; // check log status - is logging disabled ? do_cmd(CMD_LOG_STATUS, "PMTK182,3,7,", &lstatus, 2); if (lstatus) { @@ -539,12 +534,10 @@ static void mtk_read() { char cmd[256]; char* line = nullptr; - unsigned char crc, *data = nullptr; - int cmdLen, i, len, rc, init_scan, retry_cnt, log_enabled; - unsigned int j, bsize, scan_bsize, read_bsize_kb, read_bsize, scan_step, ff_len, null_len, chunk_size; - unsigned int line_size, data_size, data_addr, addr, addr_max, rcvd_addr, rcvd_bsize; - unsigned long dsize, dpos = 0; - FILE* dout; + unsigned char* data = nullptr; + int i; + unsigned int bsize; + unsigned long dpos = 0; char* fusage = nullptr; @@ -553,9 +546,9 @@ static void mtk_read() return; } - log_enabled = 0; - init_scan = 0; - dout = ufopen(TEMP_DATA_BIN, "r+b"); + int log_enabled = 0; + int init_scan = 0; + FILE* dout = ufopen(TEMP_DATA_BIN, "r+b"); if (dout == nullptr) { dout = ufopen(TEMP_DATA_BIN, "wb"); if (dout == nullptr) { @@ -565,7 +558,7 @@ static void mtk_read() } } fseek(dout, 0L,SEEK_END); - dsize = ftell(dout); + unsigned long dsize = ftell(dout); if (dsize > 1024) { dbg(1, "Temp %s file exists. with size %d\n", qPrintable(TEMP_DATA_BIN), dsize); @@ -590,7 +583,7 @@ static void mtk_read() } gb_sleep(100*1000); - addr_max = 0; + unsigned int addr_max = 0; // get flash usage, current log address..cmd only works if log disabled. do_cmd("$PMTK182,2,8*33\r\n", "PMTK182,3,8,", &fusage, 2); if (fusage) { @@ -621,25 +614,25 @@ static void mtk_read() } } - scan_step = 0x10000; - scan_bsize = 0x0400; - read_bsize_kb = strtol(OPT_block_size_kb, nullptr, 10); + unsigned int scan_step = 0x10000; + unsigned int scan_bsize = 0x0400; + unsigned int read_bsize_kb = strtol(OPT_block_size_kb, nullptr, 10); if (errno == ERANGE || read_bsize_kb < 1) { read_bsize_kb = 1; } else if (read_bsize_kb > 64) { read_bsize_kb = 64; } - read_bsize = read_bsize_kb * 1024; + unsigned int read_bsize = read_bsize_kb * 1024; dbg(2, "Download block size is %d bytes\n", read_bsize); if (init_scan) { bsize = scan_bsize; } else { bsize = read_bsize; } - addr = 0x0000; + unsigned int addr = 0x0000; - line_size = 2*read_bsize + 32; // logdata as nmea/hex. - data_size = read_bsize + 32; + unsigned int line_size = 2*read_bsize + 32; // logdata as nmea/hex. + unsigned int data_size = read_bsize + 32; if ((line = (char*) xmalloc(line_size)) == nullptr) { fatal(MYNAME ": Can't allocate %u bytes for NMEA buffer\n", line_size); } @@ -648,12 +641,12 @@ static void mtk_read() } memset(line, '\0', line_size); memset(data, '\0', data_size); - retry_cnt = 0; + int retry_cnt = 0; while (init_scan || addr < addr_max) { // generate - read address NMEA command, add crc. - crc = 0; - cmdLen = snprintf(cmd, sizeof(cmd), "$PMTK182,7,%.8x,%.8x", addr, bsize); + unsigned char crc = 0; + int cmdLen = snprintf(cmd, sizeof(cmd), "$PMTK182,7,%.8x,%.8x", addr, bsize); for (i=1; i 0) { line[len] = '\0'; if (strncmp(line, "$PMTK182,8", 10) == 0) { // $PMTK182,8,00005000,FFFFFFF retry_cnt = 0; - data_addr = strtoul(&line[11], nullptr, 16); + unsigned int data_addr = strtoul(&line[11], nullptr, 16); // fixme - we should check if all data before data_addr is already received i = 20; - j = data_addr - addr; - ff_len = 0; // number of 0xff bytes. - null_len = 0; // number of 0x00 bytes. + unsigned int j = data_addr - addr; + unsigned int ff_len = 0; // number of 0xff bytes. + unsigned int null_len = 0; // number of 0x00 bytes. while (i + 3 < len && j < data_size) { data[j] = (isdigit(line[i])?(line[i]-'0'):(line[i]-'A'+0xA))*0x10 + (isdigit(line[i+1])?(line[i+1]-'0'):(line[i+1]-'A'+0xA)); @@ -700,7 +693,7 @@ mtk_retry: j++; } rcvd_addr = addr + j; - chunk_size = rcvd_addr - data_addr; + unsigned int chunk_size = rcvd_addr - data_addr; if (init_scan) { if (ff_len == chunk_size) { // data in sector - we've found max sector.. addr_max = data_addr; @@ -731,7 +724,7 @@ mtk_retry: } } while (rcvd_addr < addr + bsize); - rcvd_bsize = rcvd_addr - addr; + unsigned int rcvd_bsize = rcvd_addr - addr; dbg(2, "Received %d bytes\n", rcvd_bsize); if (init_scan) { @@ -762,8 +755,7 @@ mtk_retry: } addr += rcvd_bsize; if (global_opts.verbose_status || (global_opts.debug_level >= 2 && global_opts.debug_level < 5)) { - int perc; - perc = 100 - 100*(addr_max-addr)/addr_max; + int perc = 100 - 100*(addr_max-addr)/addr_max; if (addr >= addr_max) { perc = 100; } @@ -994,11 +986,10 @@ static void mtk_csv_deinit() /* Output a single data line in MTK application compatible format - i.e ignore any locale settings... */ static int csv_line(gbfile* csvFile, int idx, unsigned long bmask, struct data_item* itm) { - struct tm* ts_tm; char ts_str[30]; const char* fix_str = ""; - ts_tm = gmtime(&(itm->timestamp)); + struct tm* ts_tm = gmtime(&(itm->timestamp)); strftime(ts_str, sizeof(ts_str)-1, "%Y/%m/%d,%H:%M:%S", ts_tm); if (bmask & (1< 32) { @@ -1517,15 +1513,14 @@ static int is_holux_string(const unsigned char* data, int dataLen) static void file_read() { - long fsize, pos; -// int i, j, k, bLen; + // int i, j, k, bLen; unsigned char buf[512]; memset(buf, '\0', sizeof(buf)); /* Get size of file to parse */ fseek(fl, 0L, SEEK_END); - fsize = ftell(fl); + long fsize = ftell(fl); if (fsize <= 0) { fatal(MYNAME ": File has size %ld\n", fsize); } @@ -1544,13 +1539,12 @@ static void file_read() */ int j = 0; - pos = 0; + long pos = 0; /* get default bitmask, log period/speed/distance */ int bLen = fread(buf, 1, 20, fl); if (bLen == 20) { - unsigned int mask, log_period, log_distance, log_speed, log_policy; - log_policy = le_read16(buf + 6); + unsigned int log_policy = le_read16(buf + 6); if (!(log_policy == 0x0104 || log_policy == 0x0106) && fsize > 0x10000) { dbg(1, "Invalid initial log policy 0x%.4x - check next block\n", log_policy); @@ -1558,13 +1552,13 @@ static void file_read() bLen = fread(buf, 1, 20, fl); log_policy = le_read16(buf + 6); } - mask = le_read32(buf + 2); + unsigned int mask = le_read32(buf + 2); if (mtk_device != MTK_LOGGER) { // clear Holux-specific 'low precision' bit mask &= 0x7fffffffU; } - log_period = le_read32(buf + 8); - log_distance = le_read32(buf + 12); - log_speed = le_read32(buf + 16); + unsigned int log_period = le_read32(buf + 8); + unsigned int log_distance = le_read32(buf + 12); + unsigned int log_speed = le_read32(buf + 16); dbg(1, "Default Bitmask %.8x, Log every %.0f sec, %.0f m, %.0f km/h\n", mask, log_period/10., log_distance/10., log_speed/10.); diff --git a/navicache.cc b/navicache.cc index a9d3678a2..1201ce827 100644 --- a/navicache.cc +++ b/navicache.cc @@ -99,8 +99,7 @@ NaviReadCache(const QXmlStreamReader& reader) { const QXmlStreamAttributes a = reader.attributes(); Waypoint* wpt_tmp = new Waypoint; - geocache_data* gc_data; - gc_data = wpt_tmp->AllocGCData(); + geocache_data* gc_data = wpt_tmp->AllocGCData(); if (a.hasAttribute("cache_id")) { int n = a.value("cache_id").toString().toInt(); QString fn = QString("N%1").arg(n, 5, 16, QChar('0')); diff --git a/naviguide.cc b/naviguide.cc index ef662fbde..3dcc7e33f 100644 --- a/naviguide.cc +++ b/naviguide.cc @@ -110,11 +110,11 @@ arglist_t ng_args[] = { static void ng_convert_datum(Waypoint* wpt) { - double lat, lon, east, north, alt; + double lat, lon; - east = (double) WPNC.wp_data.East; - north = (double) WPNC.wp_data.North; - alt = (double) WPNC.wp_data.Alt; + double east = (double) WPNC.wp_data.East; + double north = (double) WPNC.wp_data.North; + double alt = (double) WPNC.wp_data.Alt; GPS_Math_ICS_EN_To_WGS84(east, north, &lat, &lon); wpt->latitude = lat; @@ -129,11 +129,10 @@ ng_convert_datum(Waypoint* wpt) static void ng_fwrite_wp_data(const QString& s, const QString& d, ng_wp_data_t* wp_data, gbfile* f) { - int i; char z[50]; memset(z, 0, 50); - i = strlen(STRFROMUNICODE(s)); + int i = strlen(STRFROMUNICODE(s)); gbfputc(i, f); gbfwrite(STRFROMUNICODE(s), 1, i, f); @@ -160,9 +159,6 @@ ng_fwrite_next_wp(ng_next_wp_t* nwp, gbfile* f) static void ng_fread_wp_data(char* d, ng_wp_no_comment_t* wpnc, gbfile* f) { - - int i; - gbfread(&wpnc->chHeaderLen ,sizeof(wpnc->chHeaderLen), 1, f); gbfread(&wpnc->strName, wpnc->chHeaderLen, 1, f); wpnc->strName[wpnc->chHeaderLen] = 0; @@ -174,7 +170,7 @@ ng_fread_wp_data(char* d, ng_wp_no_comment_t* wpnc, gbfile* f) gbfread(&wpnc->wp_data.pad2,2, 1, f); wpnc->wp_data.Alt = gbfgetint32(f); gbfread(&wpnc->wp_data.CommentLength, 1, 1, f); - i = (int)wpnc->wp_data.CommentLength; + int i = (int)wpnc->wp_data.CommentLength; /* Read the comment field */ diff --git a/navilink.cc b/navilink.cc index 365cb59d9..c4d4edaa8 100644 --- a/navilink.cc +++ b/navilink.cc @@ -293,7 +293,6 @@ read_packet(unsigned type, void* payload, int handle_nak) { unsigned size; - unsigned char* data; unsigned checksum; if (read_word() != 0xa2a0) { @@ -305,7 +304,7 @@ read_packet(unsigned type, void* payload, fatal(MYNAME ": Protocol error: Packet too short\n"); } - data = (unsigned char*) xmalloc(size); + unsigned char* data = (unsigned char*) xmalloc(size); if (gbser_read_wait(serial_handle, data, size, SERIAL_TIMEOUT) != size) { fatal(MYNAME ": Read error reading %d byte payload\n", size); @@ -468,7 +467,6 @@ serial_read_waypoints() { Waypoint** waypts = nullptr; unsigned char information[32]; - unsigned short total; if (global_opts.masked_objective & RTEDATAMASK) { waypts = (Waypoint**) xcalloc(MAX_WAYPOINTS, sizeof(Waypoint*)); @@ -479,12 +477,11 @@ serial_read_waypoints() sizeof(information), sizeof(information), FALSE); - total = le_read16(information + 0); + unsigned short total = le_read16(information + 0); for (unsigned short start = 0; start < total; start += 32) { unsigned short count = total - start; unsigned char payload[7]; - unsigned char* waypoints; if (count > 32) { count = 32; @@ -496,7 +493,7 @@ serial_read_waypoints() write_packet(PID_QRY_WAYPOINTS, payload, sizeof(payload)); - waypoints = (unsigned char*) xmalloc(count * 32); + unsigned char* waypoints = (unsigned char*) xmalloc(count * 32); read_packet(PID_DATA, waypoints, count * 32, count * 32, FALSE); @@ -544,25 +541,21 @@ static void serial_read_track() { unsigned char information[32]; - unsigned int address; - unsigned short total; - route_head* track; write_packet(PID_QRY_INFORMATION, nullptr, 0); read_packet(PID_DATA, information, sizeof(information), sizeof(information), FALSE); - address = le_read32(information + 4); - total = le_read16(information + 12); + unsigned int address = le_read32(information + 4); + unsigned short total = le_read16(information + 12); - track = route_head_alloc(); + route_head* track = route_head_alloc(); track_add_head(track); while (total > 0) { unsigned short count = total < MAX_READ_TRACKPOINTS ? total : MAX_READ_TRACKPOINTS; unsigned char payload[7]; - unsigned char* trackpoints; le_write32(payload + 0, address); le_write16(payload + 4, count * 32); @@ -570,7 +563,7 @@ serial_read_track() write_packet(PID_READ_TRACKPOINTS, payload, sizeof(payload)); - trackpoints = (unsigned char*) xmalloc(count * 32); + unsigned char* trackpoints = (unsigned char*) xmalloc(count * 32); read_packet(PID_DATA, trackpoints, count * 32, count * 32, FALSE); write_packet(PID_ACK, nullptr, 0); @@ -590,8 +583,6 @@ static void serial_write_track() { unsigned char information[32]; - unsigned int address; - unsigned short total; unsigned char data[7]; write_packet(PID_QRY_INFORMATION, nullptr, 0); @@ -599,8 +590,8 @@ serial_write_track() sizeof(information), sizeof(information), FALSE); - address = le_read32(information + 4); - total = le_read16(information + 12); + unsigned int address = le_read32(information + 4); + unsigned short total = le_read16(information + 12); le_write32(data + 0, address + total * 32); le_write16(data + 4, track_data_ptr - track_data); @@ -648,19 +639,17 @@ static void serial_read_routes(Waypoint** waypts) { unsigned char information[32]; - unsigned char routec; write_packet(PID_QRY_INFORMATION, nullptr, 0); read_packet(PID_DATA, information, sizeof(information), sizeof(information), FALSE); - routec = information[2]; + unsigned char routec = information[2]; for (unsigned char r = 0; r < routec; r++) { unsigned char payload[7]; unsigned char routedata[320]; - route_head* route; le_write32(payload + 0, r); le_write16(payload + 2, 0); @@ -669,7 +658,7 @@ serial_read_routes(Waypoint** waypts) write_packet(PID_QRY_ROUTE, payload, sizeof(payload)); read_packet(PID_DATA, routedata, 64, sizeof(routedata), FALSE); - route = route_head_alloc(); + route_head* route = route_head_alloc(); route->rte_num = routedata[2]; route->rte_name = xstrdup((char*)routedata + 4); route_add_head(route); @@ -722,12 +711,9 @@ serial_write_route_point(const Waypoint* waypt) static void serial_write_route_end(const route_head* route) { - unsigned char* data; - unsigned src; unsigned char id[1]; - QString rte_name; - rte_name = route->rte_name; + QString rte_name = route->rte_name; if (rte_name == nullptr) { rte_name = "NO NAME"; } @@ -735,8 +721,8 @@ serial_write_route_end(const route_head* route) fatal(MYNAME ": Route %s too long\n", qPrintable(route->rte_name)); } - src = (route_id_ptr + MAX_SUBROUTE_LENGTH) / MAX_SUBROUTE_LENGTH; - data = (unsigned char*) xmalloc(32 + src * 32); + unsigned src = (route_id_ptr + MAX_SUBROUTE_LENGTH) / MAX_SUBROUTE_LENGTH; + unsigned char* data = (unsigned char*) xmalloc(32 + src * 32); le_write16(data + 0, 0x2000); data[2] = 0; @@ -802,7 +788,6 @@ decode_sbp_datetime_packed(const unsigned char* buffer) * SSSSSSMM MMMMHHHH Hdddddmm mmmmmmmm */ - int months; struct tm tm; memset(&tm, 0, sizeof(tm)); @@ -811,7 +796,7 @@ decode_sbp_datetime_packed(const unsigned char* buffer) tm.tm_min = ((buffer[0] & 0xC0) >> 6) | ((buffer[1] & 0x0F) << 2); tm.tm_hour = ((buffer[1] & 0xF0) >> 4) | ((buffer[2] & 0x01) << 4); tm.tm_mday = (buffer[2] & 0x3E) >> 1; - months = ((buffer[2] & 0xC0) >> 6) | buffer[3] << 2; + int months = ((buffer[2] & 0xC0) >> 6) | buffer[3] << 2; tm.tm_mon = months % 12 - 1; tm.tm_year = 100 + months / 12; @@ -854,18 +839,14 @@ read_datalog_info(unsigned int* seg1_addr, unsigned int* seg1_len, unsigned int* seg2_addr, unsigned int* seg2_len) { unsigned char info[16]; - unsigned int flash_start_addr; - unsigned int flash_length; - unsigned int data_start_addr; - unsigned int next_blank_addr; write_packet(PID_INFO_DATALOG, nullptr, 0); read_packet(PID_DATA, info, sizeof(info), sizeof(info), FALSE); - flash_start_addr = le_read32(info); - flash_length = le_read32(info + 4); - data_start_addr = le_read32(info + 8); - next_blank_addr = le_read32(info + 12); + unsigned int flash_start_addr = le_read32(info); + unsigned int flash_length = le_read32(info + 4); + unsigned int data_start_addr = le_read32(info + 8); + unsigned int next_blank_addr = le_read32(info + 12); if (data_start_addr > next_blank_addr) { /* usually there are two segments to be read */ @@ -919,7 +900,6 @@ read_datalog_records(route_head* track, static void serial_read_datalog() { - route_head* track; unsigned int seg1_addr; unsigned int seg1_len; unsigned int seg2_addr; @@ -927,7 +907,7 @@ serial_read_datalog() read_datalog_info(&seg1_addr, &seg1_len, &seg2_addr, &seg2_len); - track = route_head_alloc(); + route_head* track = route_head_alloc(); track_add_head(track); if (seg1_len) { diff --git a/navitel.cc b/navitel.cc index d9dc54f6f..d871e6775 100644 --- a/navitel.cc +++ b/navitel.cc @@ -48,20 +48,16 @@ navitel_rd_deinit() static void navitel_read_track() { - int points; route_head* trk = nullptr; - points = gbfgetint32(fin); + int points = gbfgetint32(fin); (void) gbfgetint32(fin); /* unknown */ for (int i = 0; i < points; i++) { - int lat, lon; - Waypoint* wpt; + int lon = gbfgetint32(fin); + int lat = gbfgetint32(fin); - lon = gbfgetint32(fin); - lat = gbfgetint32(fin); - - wpt = new Waypoint; + Waypoint* wpt = new Waypoint; wpt->latitude = GPS_Math_Semi_To_Deg(lat & 0x7FFFFFFF); wpt->longitude = GPS_Math_Semi_To_Deg(lon); @@ -100,10 +96,8 @@ navitel_disp_trk_head(const route_head*) static void navitel_disp_trkpts(const Waypoint* wpt) { - int lat, lon; - - lat = GPS_Math_Deg_To_Semi(wpt->latitude); - lon = GPS_Math_Deg_To_Semi(wpt->longitude); + int lat = GPS_Math_Deg_To_Semi(wpt->latitude); + int lon = GPS_Math_Deg_To_Semi(wpt->longitude); if (new_track) { lat |= (1 << 31); diff --git a/netstumbler.cc b/netstumbler.cc index 8d1038f99..3b43f9d17 100644 --- a/netstumbler.cc +++ b/netstumbler.cc @@ -85,7 +85,6 @@ data_read() char mac[2 + 17 + 2 + 1]; /* "( " + MAC + " )" + null */ char desc[sizeof ssid - 1 + 15 + 1]; /* room for channel/speed */ double lat = 0, lon = 0; - Waypoint* wpt_tmp; int line_no = 0; int stealth_num = 0, whitespace_num = 0; long flags = 0; @@ -96,8 +95,8 @@ data_read() memset(&tm, 0, sizeof(tm)); while ((ibuf = gbfgetstr(file_in))) { - char* field; - int field_num, len, stealth = 0; + int len; + int stealth = 0; if ((line++ == 0) && file_in->unicode) { cet_convert_init(CET_CHARSET_UTF8, 1); @@ -125,9 +124,9 @@ data_read() continue; } - field_num = 0; + int field_num = 0; line_no++; - field = csv_lineparse(ibuf, "\t", "", line_no); + char* field = csv_lineparse(ibuf, "\t", "", line_no); while (field) { switch (field_num) { @@ -212,7 +211,7 @@ data_read() continue; } - wpt_tmp = new Waypoint; + Waypoint* wpt_tmp = new Waypoint; if (stealth) { if (!snmac) { @@ -292,14 +291,13 @@ static void fix_netstumbler_dupes() { - int i, ct = waypt_count(), serial = 0; - htable_t* htable, *bh; + int ct = waypt_count(), serial = 0; unsigned long last_crc; - htable = (htable_t*) xmalloc(ct * sizeof *htable); - bh = htable; + htable_t* htable = (htable_t*) xmalloc(ct * sizeof *htable); + htable_t* bh = htable; - i = 0; + int i = 0; #if NEWQ // Why, oh, why is this format running over the entire waypoint list and // modifying it? This seems wrong. diff --git a/nmea.cc b/nmea.cc index 38b89ba89..8a5ec4312 100644 --- a/nmea.cc +++ b/nmea.cc @@ -286,10 +286,9 @@ nmea_rd_init(const QString& fname) * it as one waypoint. */ if (getposn) { - Waypoint* wpt; posn_status st; nmea_rd_posn_init(fname); - wpt = nmea_rd_posn(&st); + Waypoint* wpt = nmea_rd_posn(&st); if (!wpt) { return; } @@ -461,7 +460,7 @@ gpgga_parse(char* ibuf) if (fields.size() > 8) hdop = fields[8].toDouble(); double alt = unknown_alt; if (fields.size() > 9) alt = fields[9].toDouble(); - QChar altunits; + QChar altunits ='M'; if (fields.size() > 10) altunits = fields[10][0]; double geoidheight = unknown_alt; if (fields.size() > 11) geoidheight = fields[11].toDouble(); @@ -829,7 +828,6 @@ pcmpt_parse(char* ibuf) ENQUEUE_HEAD(&pcmpt_head, &curr_waypt->Q); } else { queue* elem, *tmp; - route_head* trk_head; if (QUEUE_EMPTY(&pcmpt_head)) { return; @@ -840,7 +838,7 @@ pcmpt_parse(char* ibuf) * we can rip through the queue forward now to get our * handy-dandy reversing effect. */ - trk_head = route_head_alloc(); + route_head* trk_head = route_head_alloc(); track_add_head(trk_head); QUEUE_FOR_EACH(&pcmpt_head, elem, tmp) { Waypoint* wpt = (Waypoint*) dequeue(elem); @@ -859,7 +857,6 @@ nmea_fix_timestamps(route_head* track) if (tm.tm_year == 0) { queue* elem, *temp; Waypoint* prev = nullptr; - time_t delta_tm; if (optdate == nullptr) { warning(MYNAME ": No date found within track (all points dropped)!\n"); @@ -867,7 +864,7 @@ nmea_fix_timestamps(route_head* track) track_del_head(track); return; } - delta_tm = mkgmtime(&opt_tm); + time_t delta_tm = mkgmtime(&opt_tm); QUEUE_FOR_EACH(&track->waypoint_list, elem, temp) { Waypoint* wpt = (Waypoint*)elem; @@ -881,13 +878,11 @@ nmea_fix_timestamps(route_head* track) prev = wpt; } } else { - time_t prev; - tm.tm_hour = 23; /* last date found */ tm.tm_min = 59; tm.tm_sec = 59; - prev = mkgmtime(&tm); + time_t prev = mkgmtime(&tm); /* go backward through the track and complete timestamps */ @@ -895,11 +890,9 @@ nmea_fix_timestamps(route_head* track) Waypoint* wpt = (Waypoint*)elem; if (wpt->wpt_flags.fmt_use != 0) { - time_t dt; - wpt->wpt_flags.fmt_use = 0; /* reset flag */ - dt = (prev / SECONDS_PER_DAY) * SECONDS_PER_DAY; + time_t dt = (prev / SECONDS_PER_DAY) * SECONDS_PER_DAY; wpt->creation_time += dt; if (wpt->creation_time.toTime_t() > prev) { wpt->creation_time+=SECONDS_PER_DAY; @@ -927,7 +920,6 @@ return strncmp(s1,"$",1) || strncmp(s1+3,sentenceFormatterMnemonicCode,3) || str static void nmea_parse_one_line(char* ibuf) { - char* ck; char* tbuf = lrtrim(ibuf); /* @@ -942,7 +934,7 @@ nmea_parse_one_line(char* ibuf) return; } - ck = strrchr(tbuf, '*'); + char* ck = strrchr(tbuf, '*'); if (ck != nullptr) { *ck = '\0'; int ckval = nmea_cksum(&tbuf[1]); @@ -1045,8 +1037,6 @@ nmea_read() curr_waypt = nullptr; while ((ibuf = gbfgetstr(file_in))) { - char* sdatum, *cx; - line++; if ((line == 0) & file_in->unicode) { @@ -1064,11 +1054,10 @@ nmea_read() */ /* Check the GPS datum */ - cx = strchr(&ibuf[12], '/'); + char* cx = strchr(&ibuf[12], '/'); if (cx != nullptr) { - char* edatum; - sdatum = cx + 1; - edatum = strchr(sdatum, '/'); + char* sdatum = cx + 1; + char* edatum = strchr(sdatum, '/'); if (edatum) { *edatum = 0; } @@ -1134,7 +1123,6 @@ int hunt_sirf() char ibuf[1024]; for (brp = br; *brp > 0; brp++) { - int rv; if (global_opts.debug_level > 1) { fprintf(stderr, "Trying %d\n", *brp); } @@ -1146,8 +1134,8 @@ int hunt_sirf() gbser_set_speed(gbser_handle, *brp); reset_sirf_to_nmea(*brp); - rv = gbser_read_line(gbser_handle, ibuf, sizeof(ibuf), - 1000, 0x0a, 0x0d); + int rv = gbser_read_line(gbser_handle, ibuf, sizeof(ibuf), + 1000, 0x0a, 0x0d); /* * If we didn't get a read error but did get a string that * started with a dollar sign, we're probably in NMEA mode @@ -1182,9 +1170,8 @@ nmea_rd_posn(posn_status*) */ for (int i = 0; i < 10; i++) { - int rv; ibuf[0] = 0; - rv = gbser_read_line(gbser_handle, ibuf, sizeof(ibuf), 2000, 0x0a, 0x0d); + int rv = gbser_read_line(gbser_handle, ibuf, sizeof(ibuf), 2000, 0x0a, 0x0d); if (global_opts.debug_level > 1) { safe_print(strlen(ibuf), ibuf); } @@ -1224,12 +1211,10 @@ static void nmea_wayptpr(const Waypoint* wpt) { char obuf[200]; - double lat,lon; QString s; - int cksum; - lat = degrees2ddmm(wpt->latitude); - lon = degrees2ddmm(wpt->longitude); + double lat = degrees2ddmm(wpt->latitude); + double lon = degrees2ddmm(wpt->longitude); if (global_opts.synthesize_shortnames) { s = mkshort_from_wpt(mkshort_handle, wpt); } else { @@ -1240,7 +1225,7 @@ nmea_wayptpr(const Waypoint* wpt) fabs(lat), lat < 0 ? 'S' : 'N', fabs(lon), lon < 0 ? 'W' : 'E', CSTRc(s) ); - cksum = nmea_cksum(obuf); + int cksum = nmea_cksum(obuf); gbfprintf(file_out, "$%s*%02X\n", obuf, cksum); if (sleepus >= 0) { gbfflush(file_out); @@ -1258,9 +1243,7 @@ nmea_trackpt_pr(const Waypoint* wpt) { char obuf[200]; char fix='0'; - double lat,lon; int cksum; - struct tm* tm; time_t hms; time_t ymd; @@ -1279,11 +1262,11 @@ nmea_trackpt_pr(const Waypoint* wpt) last_time = wpt->GetCreationTime().toTime_t(); } - lat = degrees2ddmm(wpt->latitude); - lon = degrees2ddmm(wpt->longitude); + double lat = degrees2ddmm(wpt->latitude); + double lon = degrees2ddmm(wpt->longitude); time_t ct = wpt->GetCreationTime().toTime_t(); - tm = gmtime(&ct); + struct tm* tm = gmtime(&ct); if (tm) { hms = tm->tm_hour * 10000 + tm->tm_min * 100 + tm->tm_sec; ymd = tm->tm_mday * 10000 + tm->tm_mon * 100 + tm->tm_year; diff --git a/nmn4.cc b/nmn4.cc index 0520cec32..476f9d719 100644 --- a/nmn4.cc +++ b/nmn4.cc @@ -65,23 +65,18 @@ static void nmn4_read_data() { char* buff; - char* str; - QString c; - int column; int line = 0; - QString zip1, zip2, city, street, number; - route_head* route; - Waypoint* wpt; + QString zip2, city, street, number; - route = route_head_alloc(); + route_head* route = route_head_alloc(); route_add_head(route); while ((buff = gbfgetstr(fin))) { if ((line++ == 0) && fin->unicode) { cet_convert_init(CET_CHARSET_UTF8, 1); } - str = buff = lrtrim(buff); + char* str = buff = lrtrim(buff); if (*buff == '\0') { continue; } @@ -89,12 +84,12 @@ nmn4_read_data() nmn4_check_line(buff); /* for a quiet compiler */ - zip1 = zip2 = city = street = number = QString(); + QString zip1 = zip2 = city = street = number = QString(); - wpt = new Waypoint; + Waypoint* wpt = new Waypoint; - column = -1; - c = csv_lineparse(str, "|", "", column++); + int column = -1; + QString c = csv_lineparse(str, "|", "", column++); while (c != nullptr) { switch (column) { case 0: /* "-" */ /* unknown fields for the moment */ diff --git a/osm.cc b/osm.cc index c35641bf7..b973be65b 100644 --- a/osm.cc +++ b/osm.cc @@ -439,12 +439,11 @@ static QString osm_feature_symbol(const int ikey, const char* value) { char buff[128]; - QString key; buff[0] = ikey; strncpy(&buff[1], value, sizeof(buff) - 1); - key = QString::fromUtf8(buff); + QString key = QString::fromUtf8(buff); QString result; if (values.contains(key)) { @@ -523,7 +522,6 @@ static void osm_node_tag(xg_string, const QXmlStreamAttributes* attrv) { QString key, value; - QString str; signed char ikey; if (attrv->hasAttribute("k")) { @@ -533,7 +531,7 @@ osm_node_tag(xg_string, const QXmlStreamAttributes* attrv) value = attrv->value("v").toString(); } - str = osm_strip_html(value); + QString str = osm_strip_html(value); if (key == QLatin1String("name")) { if (wpt->shortname.isEmpty()) { @@ -605,7 +603,6 @@ static void osm_way_tag(xg_string, const QXmlStreamAttributes* attrv) { QString key, value; - QString str; signed char ikey; if (attrv->hasAttribute("k")) { @@ -615,7 +612,7 @@ osm_way_tag(xg_string, const QXmlStreamAttributes* attrv) value = attrv->value("v").toString(); } - str = osm_strip_html(value); + QString str = osm_strip_html(value); if (key == QLatin1String("name")) { if (rte->rte_name.isEmpty()) { @@ -736,14 +733,14 @@ osm_disp_feature(const Waypoint* wpt) static void osm_write_opt_tag(const char* atag) { - char* tag, *cin, *ce; + char* cin; if (!atag) { return; } - tag = cin = xstrdup(atag); - ce = cin + strlen(cin); + char* tag = cin = xstrdup(atag); + char* ce = cin + strlen(cin); while (cin < ce) { char* sc, *dp; @@ -793,9 +790,7 @@ osm_waypt_disp(const Waypoint* wpt) waypoints.insert(name, wpt); - int* id; - - id = (int*) xmalloc(sizeof(*id)); + int* id = (int*) xmalloc(sizeof(*id)); *id = --node_id; (const_cast(wpt))->extra_data = id; diff --git a/ozi.cc b/ozi.cc index d196a5ea1..51d0d7356 100644 --- a/ozi.cc +++ b/ozi.cc @@ -719,8 +719,6 @@ data_read() { QString buff; char* trk_name = nullptr; - Waypoint* wpt_tmp; - int i; int linecount = 0; while ((buff = gbfgetstr(file_in)), !buff.isNull()) { @@ -776,13 +774,13 @@ data_read() if (buff.contains(',')) { bool ozi_fsdata_used = false; ozi_fsdata* fsdata = ozi_alloc_fsdata(); - wpt_tmp = new Waypoint; + Waypoint* wpt_tmp = new Waypoint; /* data delimited by commas, possibly enclosed in quotes. */ char* orig_s = xstrdup(CSTR(buff)); char* s = csv_lineparse(orig_s, ",", "", linecount); - i = 0; + int i = 0; bool header = false; while (s) { switch (ozi_objective) { diff --git a/parse.cc b/parse.cc index 125f8704a..1779f82b7 100644 --- a/parse.cc +++ b/parse.cc @@ -167,11 +167,12 @@ parse_coordinates(const char* str, int datum, const grid_type grid, int utmz; double utme, utmn; char utmc; - int valid, result, ct; + int result; + int ct; double lx, ly; const char* format; - valid = 1; + int valid = 1; switch (grid) { diff --git a/pcx.cc b/pcx.cc index 4ead2f5ec..677c233fc 100644 --- a/pcx.cc +++ b/pcx.cc @@ -100,11 +100,10 @@ static void data_read() { char* buff; route_head* track = nullptr; route_head* route = nullptr; - int points; int line_number = 0; read_as_degrees = 0; - points = 0; + int points = 0; // Each line is both |buff| as a C string and |line| as a QString. while ((buff = gbfgetstr(file_in))) { @@ -293,11 +292,10 @@ static void data_read() { } static void gpsutil_disp(const Waypoint* wpt) { - double lon, lat; int icon_token = 0; - lon = degrees2ddmm(wpt->longitude); - lat = degrees2ddmm(wpt->latitude); + double lon = degrees2ddmm(wpt->longitude); + double lat = degrees2ddmm(wpt->latitude); QDateTime dt = wpt->GetCreationTime().toUTC(); const QString ds = dt.toString("dd-MMM-yy hh:mm:ss").toUpper(); @@ -357,10 +355,8 @@ static void pcx_route_hdr(const route_head* rte) { } static void pcx_track_disp(const Waypoint* wpt) { - double lon, lat; - - lon = degrees2ddmm(wpt->longitude); - lat = degrees2ddmm(wpt->latitude); + double lon = degrees2ddmm(wpt->longitude); + double lat = degrees2ddmm(wpt->latitude); QDateTime dt = wpt->GetCreationTime().toUTC(); const QString ds = dt.toString("dd-MMM-yy hh:mm:ss").toUpper(); diff --git a/pocketfms_bc.cc b/pocketfms_bc.cc index d32deed50..442002256 100644 --- a/pocketfms_bc.cc +++ b/pocketfms_bc.cc @@ -90,7 +90,6 @@ read_tracks() while (1 == gbfread(&bc, sizeof(bc), 1, file_in)) { struct tm tm; - Waypoint* wpt; if (strcmp(bc.id, header_id) != 0) { fatal(MYNAME ": invalid breadcrumb header in input file.\n"); @@ -104,7 +103,7 @@ read_tracks() tm.tm_min = le_readu16(&bc.minute); tm.tm_sec = le_readu16(&bc.second); - wpt = new Waypoint; + Waypoint* wpt = new Waypoint; wpt->latitude = le_read_float(&bc.latitude); wpt->longitude = le_read_float(&bc.longitude); wpt->altitude = FEET_TO_METERS(le_read_float(&bc.altitude)); @@ -129,11 +128,10 @@ static void pocketfms_waypt_disp(const Waypoint* wpt) { struct breadcrumb bc; - struct tm* tm; memset(&bc, 0, sizeof(bc)); const time_t tt = wpt->GetCreationTime().toTime_t(); - tm = localtime(&tt); + struct tm* tm = localtime(&tt); if (wpt->creation_time.isValid()) { const time_t tt = wpt->GetCreationTime().toTime_t(); tm = gmtime(&tt); diff --git a/pocketfms_wp.cc b/pocketfms_wp.cc index 9fae15ea5..603c4820d 100644 --- a/pocketfms_wp.cc +++ b/pocketfms_wp.cc @@ -60,15 +60,13 @@ data_read() char* buff; int linecount = 0; while ((buff = gbfgetstr(file_in))) { - char* s; - Waypoint* wpt; rtrim(buff); if (strlen(buff) == 0) { break; } linecount++; - wpt = new Waypoint; - s = buff; + Waypoint* wpt = new Waypoint; + char* s = buff; s = csv_lineparse(s, "\\w", "", linecount); if (!s) { fatal(MYNAME "Invalid name"); diff --git a/polygon.cc b/polygon.cc index f5d89c6d6..54b13f12f 100644 --- a/polygon.cc +++ b/polygon.cc @@ -218,17 +218,19 @@ void PolygonFilter::process() queue* elem, * tmp; Waypoint* waypointp; extra_data* ed; - double lat1, lon1, lat2, lon2; - double olat, olon; int fileline = 0; int first = 1; int last = 0; char* line; - gbfile* file_in; - file_in = gbfopen(polyfileopt, "r", MYNAME); + gbfile* file_in = gbfopen(polyfileopt, "r", MYNAME); - olat = olon = lat1 = lon1 = lat2 = lon2 = BADVAL; + double olat = BADVAL; + double olon = BADVAL; + double lat1 = BADVAL; + double lon1 = BADVAL; + double lat2 = BADVAL; + double lon2 = BADVAL; while ((line = gbfgetstr(file_in))) { fileline++; diff --git a/position.cc b/position.cc index 9c10ae786..035c13013 100644 --- a/position.cc +++ b/position.cc @@ -42,13 +42,11 @@ double PositionFilter::gc_distance(double lat1, double lon1, double lat2, double void PositionFilter::position_runqueue(queue* q, int nelems, int qtype) { queue* elem, * tmp; - Waypoint** comp; - int* qlist; double dist, diff_time; int i = 0, anyitem; - comp = (Waypoint**) xcalloc(nelems, sizeof(*comp)); - qlist = (int*) xcalloc(nelems, sizeof(*qlist)); + Waypoint** comp = (Waypoint**) xcalloc(nelems, sizeof(*comp)); + int* qlist = (int*) xcalloc(nelems, sizeof(*qlist)); #if NEWQ foreach (Waypoint* waypointp, waypt_list) { diff --git a/psitrex.cc b/psitrex.cc index 360ce89f7..e462073fc 100644 --- a/psitrex.cc +++ b/psitrex.cc @@ -333,8 +333,6 @@ psit_waypoint_r(gbfile* psit_file, Waypoint**) static void psit_waypoint_w(gbfile* psit_file, const Waypoint* wpt) { - int icon; - const char* ident; char* src = nullptr; /* BUGBUG Passed to mkshort */ gbfprintf(psit_file, "%11.6f,%11.6f,", @@ -347,14 +345,14 @@ psit_waypoint_w(gbfile* psit_file, const Waypoint* wpt) gbfprintf(psit_file, "%8.2f,", wpt->altitude); - ident = global_opts.synthesize_shortnames ? - mkshort(mkshort_handle, src) : - xstrdup(wpt->shortname); + const char* ident = global_opts.synthesize_shortnames ? + mkshort(mkshort_handle, src) : + xstrdup(wpt->shortname); gbfprintf(psit_file, " %-6s, ", ident); xfree(ident); - icon = gt_find_icon_number_from_desc(wpt->icon_descr, PCX); + int icon = gt_find_icon_number_from_desc(wpt->icon_descr, PCX); if (get_cache_icon(wpt) && wpt->icon_descr.compare(QLatin1String("Geocache Found")) != 0) { icon = gt_find_icon_number_from_desc(get_cache_icon(wpt), PCX); @@ -383,7 +381,6 @@ static void psit_route_r(gbfile* psit_file, route_head** rte) { char rtename[256]; - route_head* rte_head; psit_getToken(psit_file,psit_current_token,sizeof(psit_current_token), ltrimEOL); @@ -395,7 +392,7 @@ psit_route_r(gbfile* psit_file, route_head** rte) rtrim(rtename); - rte_head = route_head_alloc(); + route_head* rte_head = route_head_alloc(); rte_head->rte_name = rtename; route_add_head(rte_head); *rte = rte_head; @@ -501,10 +498,8 @@ static void psit_track_r(gbfile* psit_file, route_head**) { char trkname[256]; - unsigned int trk_num; struct tm tmTime; - Waypoint* thisWaypoint; psit_getToken(psit_file,psit_current_token,sizeof(psit_current_token), ltrimEOL); if (strlen(psit_current_token) == 0) { @@ -515,14 +510,14 @@ psit_track_r(gbfile* psit_file, route_head**) rtrim(trkname); - trk_num = 0; + unsigned int trk_num = 0; route_head* track_head = nullptr; psit_getToken(psit_file,psit_current_token,sizeof(psit_current_token), wscomma); while (psit_isKnownToken(psit_current_token) != 0) { if (strlen(psit_current_token) > 0) { - thisWaypoint = new Waypoint; + Waypoint* thisWaypoint = new Waypoint; thisWaypoint->latitude = atof(psit_current_token); diff --git a/queue.h b/queue.h index 1d0aaad96..860239ee5 100644 --- a/queue.h +++ b/queue.h @@ -111,8 +111,7 @@ void sortqueue(queue* qh, T cmp) { - queue* p, *q, *e, *tail, *oldhead, *list; - int insize, nmerges, psize, qsize, i; + queue* e; /* * Special case: if `list' is empty, we're done. @@ -126,25 +125,25 @@ sortqueue(queue* qh, T cmp) * element. So remove the list head for now. Put it back later. */ - list = QUEUE_FIRST(qh); + queue* list = QUEUE_FIRST(qh); dequeue(qh); - insize = 1; + int insize = 1; while (true) { - p = list; - oldhead = list; /* only used for circular linkage */ + queue* p = list; + queue* oldhead = list; /* only used for circular linkage */ list = nullptr; - tail = nullptr; + queue* tail = nullptr; - nmerges = 0; /* count number of merges we do in this pass */ + int nmerges = 0; /* count number of merges we do in this pass */ while (p) { nmerges++; /* there exists a merge to be done */ /* step `insize' places along from p */ - q = p; - psize = 0; - for (i = 0; i < insize; i++) { + queue* q = p; + int psize = 0; + for (int i = 0; i < insize; i++) { psize++; q = (q->next == oldhead ? nullptr : q->next); if (!q) { @@ -154,7 +153,7 @@ sortqueue(queue* qh, T cmp) /* if q hasn't fallen off end, we have * two lists to merge */ - qsize = insize; + int qsize = insize; /* now we have two lists; merge them */ while (psize > 0 || (qsize > 0 && q)) { diff --git a/random.cc b/random.cc index 2372fe30d..2e8f9622a 100644 --- a/random.cc +++ b/random.cc @@ -58,12 +58,9 @@ rand_int(const int max) static char* rand_str(const int maxlen, const char* fmt) { - char* res; - int len; + int len = rand_int(maxlen) + 1; - len = rand_int(maxlen) + 1; - - res = (char*) xmalloc(len + 1); + char* res = (char*) xmalloc(len + 1); res[len] = '\0'; for (int i = 0; i < len; i++) { @@ -111,7 +108,6 @@ random_read() { #define RND(a) (rand_int(a) > 0) - int points; route_head* head; Waypoint* prev = nullptr; time_t time = gpsbabel_time; @@ -123,7 +119,7 @@ random_read() } - points = (opt_points) ? atoi(opt_points) : rand_int(128) + 1; + int points = (opt_points) ? atoi(opt_points) : rand_int(128) + 1; if (doing_trks || doing_rtes) { head = route_head_alloc(); if (doing_trks) { @@ -142,12 +138,8 @@ random_read() } for (int i = 0; i < points; i++) { - - Waypoint* wpt; - garmin_fs_t* gmsd; - - wpt = new Waypoint; - gmsd = garmin_fs_alloc(-1); + Waypoint* wpt = new Waypoint; + garmin_fs_t* gmsd = garmin_fs_alloc(-1); fs_chain_add(&wpt->fs, (format_specific_data*) gmsd); do { diff --git a/raymarine.cc b/raymarine.cc index eca0f3c73..ae6e1872e 100644 --- a/raymarine.cc +++ b/raymarine.cc @@ -144,10 +144,7 @@ static int find_symbol_num(const QString& descr) { if (!descr.isNull()) { - - raymarine_symbol_mapping_t* a; - - a = &raymarine_symbols[0]; + raymarine_symbol_mapping_t* a = &raymarine_symbols[0]; for (unsigned int i = 0; i < RAYMARINE_SYMBOL_CT; i++, a++) { if (descr.compare(a->name, Qt::CaseInsensitive) == 0) { @@ -184,8 +181,6 @@ raymarine_rd_done() static void raymarine_read() { - Waypoint* wpt; - /* Read all waypoints */ for (unsigned int ix = 0; ix < 0x3FFF; ix++) { @@ -206,7 +201,7 @@ raymarine_read() break; } - wpt = new Waypoint; + Waypoint* wpt = new Waypoint; wpt->shortname = name; wpt->latitude = atof(lat); wpt->longitude = atof(lon); @@ -234,29 +229,26 @@ raymarine_read() for (unsigned int rx = 0; rx < 0x3FFF; rx++) { char sect[10]; char* name; - route_head* rte; snprintf(sect, sizeof(sect), "Rt%d", rx); if (nullptr == (name = inifile_readstr(fin, sect, "Name"))) { break; } - rte = route_head_alloc(); + route_head* rte = route_head_alloc(); rte->rte_name = name; route_add_head(rte); for (int wx = 0; wx < 0x3FFF; wx++) { char buff[32]; - char* str; - Waypoint* wpt; snprintf(buff, sizeof(buff), "Mk%d", wx); - str = inifile_readstr(fin, sect, buff); + char* str = inifile_readstr(fin, sect, buff); if ((str == nullptr) || (*str == '\0')) { break; } - wpt = find_waypt_by_name(str); + Waypoint* wpt = find_waypt_by_name(str); if (wpt == nullptr) fatal(MYNAME ": No associated waypoint for route point %s (Route %s)!\n", str, qPrintable(rte->rte_name)); @@ -333,11 +325,7 @@ qsort_cb(const void* a, const void* b) static void write_waypoint(gbfile* fout, const Waypoint* wpt, const int waypt_no, const char* location) { - QString notes; - char* name; - double time; - - notes = wpt->notes; + QString notes = wpt->notes; if (notes == nullptr) { notes = wpt->description; if (notes == nullptr) { @@ -345,8 +333,8 @@ write_waypoint(gbfile* fout, const Waypoint* wpt, const int waypt_no, const char } } notes = csv_stringclean(notes, LINE_FEED); - time = wpt->creation_time.isValid() ? TIMET_TO_EXCEL(wpt->GetCreationTime().toTime_t()) : TIMET_TO_EXCEL(gpsbabel_time); - name = (char*)wpt->extra_data; + double time = wpt->creation_time.isValid() ? TIMET_TO_EXCEL(wpt->GetCreationTime().toTime_t()) : TIMET_TO_EXCEL(gpsbabel_time); + char* name = (char*)wpt->extra_data; gbfprintf(fout, "[Wp%d]" LINE_FEED "Loc=%s" LINE_FEED @@ -381,9 +369,7 @@ write_waypoint(gbfile* fout, const Waypoint* wpt, const int waypt_no, const char static void write_route_head_cb(const route_head* rte) { - QString name; - - name = rte->rte_name; + QString name = rte->rte_name; if (name.isEmpty()) { name=QString("Route%1").arg(rte_index); } @@ -433,9 +419,7 @@ enum_route_hdr_cb(const route_head* rte) static short_handle raymarine_new_short_handle() { - short_handle res; - - res = mkshort_new_handle(); + short_handle res = mkshort_new_handle(); setshort_length(res, 16); setshort_badchars(res, ","); @@ -469,7 +453,6 @@ static void raymarine_write() { int i; - Waypoint* wpt; waypt_table_sz = 0; waypt_table_ct = 0; @@ -497,7 +480,7 @@ raymarine_write() /* release local used data */ for (i = 0; i < waypt_table_ct; i++) { - wpt = waypt_table[i]; + Waypoint* wpt = waypt_table[i]; xfree(wpt->extra_data); wpt->extra_data = nullptr; } diff --git a/reverse_route.cc b/reverse_route.cc index 182c04df3..8868b1a21 100644 --- a/reverse_route.cc +++ b/reverse_route.cc @@ -35,9 +35,7 @@ void ReverseRouteFilter::reverse_route_wpt(const Waypoint* waypointp) /* Cast away const-ness */ Waypoint* wpp = const_cast(waypointp); - int curr_new_trkseg; - - curr_new_trkseg = waypointp->wpt_flags.new_trkseg; + int curr_new_trkseg = waypointp->wpt_flags.new_trkseg; wpp->wpt_flags.new_trkseg = prev_new_trkseg; prev_new_trkseg = curr_new_trkseg; } diff --git a/rgbcolors.cc b/rgbcolors.cc index 54c469d34..bf939bb23 100644 --- a/rgbcolors.cc +++ b/rgbcolors.cc @@ -221,10 +221,9 @@ static int HexByte(const char* hex) int color_to_bbggrr(const char* opt_color) { - int color_num; char* ep; - color_num = strtol(opt_color, &ep, 10); + int color_num = strtol(opt_color, &ep, 10); if (ep != opt_color) { return color_num; diff --git a/route.cc b/route.cc index 21c7d1067..678cb5b53 100644 --- a/route.cc +++ b/route.cc @@ -133,10 +133,9 @@ route_head* common_route_by_name(queue* routes, const char* name) { queue* elem, *tmp; - route_head* rte; QUEUE_FOR_EACH(routes, elem, tmp) { - rte = (route_head*) elem; + route_head* rte = (route_head*) elem; if (rte->rte_name == name) { return rte; } @@ -275,8 +274,7 @@ common_disp_session(const session_t* se, queue* qh, route_hdr rh, route_trl rt, { queue* elem, *tmp; QUEUE_FOR_EACH(qh, elem, tmp) { - const route_head* rhp; - rhp = (route_head*) elem; + const route_head* rhp = (route_head*) elem; if (rhp->session == se) { if (rh) { (*rh)(rhp); @@ -305,10 +303,9 @@ static void route_flush_q(queue* head) { queue* elem, *tmp; - queue* q; QUEUE_FOR_EACH(head, elem, tmp) { - q = dequeue(elem); + queue* q = dequeue(elem); any_route_free((route_head*) q); } } @@ -340,9 +337,8 @@ void route_flush(queue* head) { queue* elem, *tmp; - queue* q; QUEUE_FOR_EACH(head, elem, tmp) { - q = dequeue(elem); + queue* q = dequeue(elem); any_route_free((route_head*)q); } } @@ -351,7 +347,6 @@ void route_copy(int* dst_count, int* dst_wpt_count, queue** dst, queue* src) { queue* elem, *tmp, *elem2, *tmp2; - route_head* rte_new; int junk; if (!dst_wpt_count) { dst_wpt_count = &junk; @@ -368,7 +363,7 @@ route_copy(int* dst_count, int* dst_wpt_count, queue** dst, queue* src) QUEUE_FOR_EACH(src, elem, tmp) { route_head* rte_old = (route_head*)elem; - rte_new = route_head_alloc(); + route_head* rte_new = route_head_alloc(); rte_new->rte_name = rte_old->rte_name; rte_new->rte_desc = rte_old->rte_desc; rte_new->rte_url = rte_old->rte_url; @@ -528,7 +523,6 @@ tracks_to_routes() void track_recompute(const route_head* trk, computed_trkdata** trkdatap) { Waypoint first; - Waypoint* thisw; Waypoint* prev = &first; queue* elem, *tmp; int tkpt = 0; @@ -550,20 +544,18 @@ void track_recompute(const route_head* trk, computed_trkdata** trkdatap) tdata->max_alt = unknown_alt; QUEUE_FOR_EACH((queue*)&trk->waypoint_list, elem, tmp) { - double tlat, tlon, plat, plon, dist; - - thisw = (Waypoint*)elem; + Waypoint* thisw = (Waypoint*)elem; /* * gcdist and heading want radians, not degrees. */ - tlat = RAD(thisw->latitude); - tlon = RAD(thisw->longitude); - plat = RAD(prev->latitude); - plon = RAD(prev->longitude); + double tlat = RAD(thisw->latitude); + double tlon = RAD(thisw->longitude); + double plat = RAD(prev->latitude); + double plon = RAD(prev->longitude); WAYPT_SET(thisw, course, heading_true_degrees(plat, plon, tlat, tlon)); - dist = radtometers(gcdist(plat, plon, tlat, tlon)); + double dist = radtometers(gcdist(plat, plon, tlat, tlon)); /* * Avoid that 6300 mile jump as we move from 0,0. diff --git a/saroute.cc b/saroute.cc index a6b0e7eb6..a07585025 100644 --- a/saroute.cc +++ b/saroute.cc @@ -115,20 +115,12 @@ rd_deinit() static void my_read() { - - uint16_t version; - uint32_t count; - uint32_t outercount; - uint32_t recsize; - uint16_t stringlen; - unsigned char* record; static int serial = 0; struct ll { int32_t lat; int32_t lon; } *latlon; struct ll mylatlon; - uint16_t coordcount; route_head* track_head = nullptr; Waypoint* wpt_tmp; char* routename = nullptr; @@ -140,7 +132,7 @@ my_read() double oldlon = 0; ReadShort(infile); /* magic */ - version = ReadShort(infile); + uint16_t version = ReadShort(infile); ReadLong(infile); if (version >= 6) { @@ -153,14 +145,14 @@ my_read() */ ReadShort(infile); - recsize = ReadLong(infile); + uint32_t recsize = ReadLong(infile); /* * the first recsize, oddly, doesn't include the filename string * but it does include the header. */ - record = ReadRecord(infile, recsize); + unsigned char* record = ReadRecord(infile, recsize); - stringlen = le_read16((uint16_t*)(record + 0x1a)); + uint16_t stringlen = le_read16((uint16_t*)(record + 0x1a)); if (stringlen) { routename = (char*)xmalloc(stringlen + 1); routename[stringlen] = '\0'; @@ -185,28 +177,25 @@ my_read() track_head->rte_name = routename; } } - count = ReadLong(infile); + uint32_t count = ReadLong(infile); while (count) { ReadShort(infile); recsize = ReadLong(infile); if (version < 6 || control) { - double lat; - double lon; - record = ReadRecord(infile, recsize); latlon = (struct ll*)(record); /* These records are backwards for some reason */ - lat = (0x80000000UL - - le_read32(&latlon->lon)) / (double)(0x800000); - lon = (0x80000000UL - - le_read32(&latlon->lat)) / (double)(0x800000); + double lat = (0x80000000UL - + le_read32(&latlon->lon)) / (double)(0x800000); + double lon = (0x80000000UL - + le_read32(&latlon->lat)) / (double)(0x800000); wpt_tmp = new Waypoint; wpt_tmp->latitude = lat; wpt_tmp->longitude = -lon; if (control) { - int obase, addrlen, cmtlen; + int obase; /* Somewhere around TopoUSA 6.0, these moved */ /* This block also seems to get miscompiled @@ -220,8 +209,8 @@ my_read() obase = 18; } - addrlen = le_read16(&record[obase]); - cmtlen = le_read16(&record[obase+2+addrlen]); + int addrlen = le_read16(&record[obase]); + int cmtlen = le_read16(&record[obase+2+addrlen]); (void) cmtlen; #if NEW_STRINGS // That we've had no bugreports on this strongly indicates this code @@ -279,7 +268,7 @@ my_read() * outercount is the number of route segments (start+end+stops+vias-1) */ - outercount = ReadLong(infile); + uint32_t outercount = ReadLong(infile); while (outercount) { /* @@ -349,8 +338,8 @@ my_read() seglen /= 5280*12*2.54/100000; /* to miles */ } - coordcount = le_read16((uint16_t*) - (record + 2 + stringlen + 0x3c)); + uint16_t coordcount = le_read16((uint16_t*) + (record + 2 + stringlen + 0x3c)); latlon = (struct ll*)(record + 2 + stringlen + 0x3c + 2); count--; if (count) { @@ -360,19 +349,16 @@ my_read() int first = 1; while (coordcount) { - double lat; - double lon; - wpt_tmp = new Waypoint; // copy to make sure we don't violate alignment restrictions. memcpy(&mylatlon,latlon,sizeof(mylatlon)); - lat = (0x80000000UL - - le_read32(&mylatlon.lat)) / - (double)(0x800000); - lon = (0x80000000UL - - le_read32(&mylatlon.lon)) / - (double)(0x800000); + double lat = (0x80000000UL - + le_read32(&mylatlon.lat)) / + (double)(0x800000); + double lon = (0x80000000UL - + le_read32(&mylatlon.lon)) / + (double)(0x800000); wpt_tmp->latitude = lat; wpt_tmp->longitude = -lon; diff --git a/sbn.cc b/sbn.cc index 4ef6eb4a0..69022614c 100644 --- a/sbn.cc +++ b/sbn.cc @@ -63,10 +63,7 @@ arglist_t sbn_args[] = { static size_t read_packet(int* type, void* payload, size_t max_len) { - size_t size, data_size; unsigned char start[4]; - unsigned int checksum_exp, checksum_act; - unsigned char* data; if (gbfread(start, sizeof(start), 1, file_handle) != 1) { if (gbfeof(file_handle)) { @@ -80,17 +77,17 @@ read_packet(int* type, void* payload, size_t max_len) fatal(MYNAME ": Format error: Bad packet start.\n"); } - size = be_readu16(start + 2); + size_t size = be_readu16(start + 2); if (size < 1 || max_len < size) { fatal(MYNAME ": Format error: unexpected size: %d.\n", (int) size); } /* allocate space for checksum and trailing 0xb0b3 */ - data_size = size + 4; + size_t data_size = size + 4; /* data_size can be up to about 64k */ - data = (unsigned char*) xmalloc(data_size); + unsigned char* data = (unsigned char*) xmalloc(data_size); if (gbfread(data, data_size, 1, file_handle) != 1) { fatal(MYNAME ": Format error: could not read %d bytes.\n", @@ -99,8 +96,8 @@ read_packet(int* type, void* payload, size_t max_len) *type = data[0]; - checksum_exp = be_readu16(data + size); - checksum_act = navilink_checksum_packet(data, size); + unsigned int checksum_exp = be_readu16(data + size); + unsigned int checksum_act = navilink_checksum_packet(data, size); if (checksum_exp != checksum_act) { fatal(MYNAME ": Checksum error - expected %x got %x\n", @@ -174,10 +171,9 @@ static void read_sbn_header(route_head*) { char header[QRY_INFORMATION_LEN]; - size_t len; int type = 0; - len = read_packet(&type, header, sizeof(header)); + size_t len = read_packet(&type, header, sizeof(header)); if (len == 0 || type != PID_QRY_INFORMATION || !locosys_decode_file_id(header, len)) { @@ -294,9 +290,7 @@ static void sbn_read() { if (global_opts.masked_objective & TRKDATAMASK) { - route_head* track; - - track = route_head_alloc(); + route_head* track = route_head_alloc(); track_add_head(track); read_sbn_header(track); diff --git a/sbp.cc b/sbp.cc index ac4aa14f4..71688545b 100644 --- a/sbp.cc +++ b/sbp.cc @@ -98,9 +98,8 @@ static void sbp_read() { Waypoint* logpoint; - route_head* track; - track = route_head_alloc(); + route_head* track = route_head_alloc(); track_add_head(track); read_sbp_header(track); diff --git a/session.cc b/session.cc index bcdb3d24a..e99fd1e91 100644 --- a/session.cc +++ b/session.cc @@ -49,14 +49,12 @@ session_exit() void start_session(const char* name, const char* filename) { - session_t* s; - if (session_ct == 0) { QUEUE_INIT(&session_list); } session_ct++; - s = (session_t*) xcalloc(1, sizeof(*s)); + session_t* s = (session_t*) xcalloc(1, sizeof(*s)); ENQUEUE_TAIL(&session_list, &s->Q); QUEUE_INIT(&s->category_list); s->nr = session_ct; diff --git a/shape.cc b/shape.cc index 1cdeb280d..4d98aedbf 100644 --- a/shape.cc +++ b/shape.cc @@ -290,12 +290,11 @@ my_read(void) SHPGetInfo(ihandle, &npts, nullptr, nullptr, nullptr); for (int iShape=0; iShape= 0) { name = DBFReadStringAttribute(ihandledb, iShape, nameidx); // } else if (nameidx == -1) { @@ -423,16 +422,14 @@ my_wr_deinit(void) static void my_write_wpt(const Waypoint* wpt) { - SHPObject* shpobject; - // note that the z coordinate (&wpt->altitude) does not apply // to SHPT_POINT. // We could potentially write SHPT_POINTZ, but we would have // to address what to do when we don't have altitude data. - shpobject = SHPCreateSimpleObject(SHPT_POINT, 1, - &wpt->longitude, - &wpt->latitude, - &wpt->altitude); + SHPObject* shpobject = SHPCreateSimpleObject(SHPT_POINT, 1, + &wpt->longitude, + &wpt->latitude, + &wpt->altitude); int iShape = SHPWriteObject(ohandle, -1, shpobject); SHPDestroyObject(shpobject); DBFWriteStringAttribute(ohandledb, iShape, nameFieldIdx, @@ -462,13 +459,12 @@ poly_point(const Waypoint* wpt) static void poly_deinit(const route_head* rte) { - SHPObject* shpobject; // note that the z coordinate (polybufz) does not apply // to SHPT_ARC. // We could potentially write SHPT_ARCZ, but we would have // to address what to do when we don't have altitude data. - shpobject = SHPCreateSimpleObject(SHPT_ARC, poly_count, - polybufx, polybufy, polybufz); + SHPObject* shpobject = SHPCreateSimpleObject(SHPT_ARC, poly_count, + polybufx, polybufy, polybufz); int iShape = SHPWriteObject(ohandle, -1, shpobject); SHPDestroyObject(shpobject); DBFWriteStringAttribute(ohandledb, iShape, nameFieldIdx, diff --git a/skyforce.cc b/skyforce.cc index ee0c2dae1..844aca784 100644 --- a/skyforce.cc +++ b/skyforce.cc @@ -44,13 +44,11 @@ static const Waypoint* prev_wpt; static Waypoint* skyforce_parse_coords(const char* str) { - Waypoint* wpt; - if (strlen(str) < 38) { fatal(MYNAME ": Incomplete line!\n"); } - wpt = new Waypoint; + Waypoint* wpt = new Waypoint; wpt->latitude = atof(str + 21); if (str[20] == 'S') { @@ -71,9 +69,7 @@ skyforce_parse_coords(const char* str) static Waypoint* skyforce_parse_wpt(const char* str, int* rte_num) { - Waypoint* wpt; - - wpt = skyforce_parse_coords(str); + Waypoint* wpt = skyforce_parse_coords(str); if (wpt == nullptr) { return nullptr; } @@ -95,11 +91,8 @@ static Waypoint* skyforce_parse_trk(const char* str) { char buf[15]; - int len; - - Waypoint* wpt; - wpt = skyforce_parse_coords(str); + Waypoint* wpt = skyforce_parse_coords(str); if (wpt == nullptr) { return nullptr; } @@ -111,7 +104,7 @@ skyforce_parse_trk(const char* str) dt = dt.addYears(100); wpt->SetCreationTime(dt); - len = strlen(str); + int len = strlen(str); if (len >= 45) { WAYPT_SET(wpt, speed, KNOTS_TO_MPS(atof(str + 39))); @@ -151,7 +144,6 @@ static void skyforce_waypt_disp_cb(const Waypoint* wpt) { char buf[75]; /* long enough for all data types */ - double lat, lon; memset(buf, ' ', sizeof(buf)); @@ -202,23 +194,23 @@ skyforce_waypt_disp_cb(const Waypoint* wpt) } - lat = degrees2ddmm(wpt->latitude); + double lat = degrees2ddmm(wpt->latitude); buf[20] = (wpt->latitude < 0) ? 'S' : 'N'; snprintf(&buf[21], sizeof(buf) - 21, "%06.2f ", fabs(lat)); - lon = degrees2ddmm(wpt->longitude); + double lon = degrees2ddmm(wpt->longitude); buf[29] = (wpt->longitude < 0) ? 'W' : 'E'; snprintf(&buf[30], sizeof(buf) - 30, "%08.2f ", fabs(lon)); if (global_opts.objective == trkdata) { - double alt, speed; + double alt; if (wpt->altitude == unknown_alt) { alt = 0; } else { alt = METERS_TO_FEET(wpt->altitude); } - speed = MPS_TO_KNOTS(waypt_speed(prev_wpt, wpt)); + double speed = MPS_TO_KNOTS(waypt_speed(prev_wpt, wpt)); snprintf(&buf[39], sizeof(buf) - 39, "%06.2f 000.00 %c%05d", speed, @@ -253,10 +245,10 @@ static void skyforce_read() { char* str; - route_head* rte, *trk; wpt_num = 0; - rte = trk = nullptr; + route_head* rte = nullptr; + route_head* trk = nullptr; rte_num = -1; while ((str = gbfgetstr(fin))) { diff --git a/skytraq.cc b/skytraq.cc index 4c60e1652..b712a9d60 100644 --- a/skytraq.cc +++ b/skytraq.cc @@ -175,18 +175,17 @@ rd_char(int* errors) static int rd_buf(const uint8_t* buf, int len) { - int rc, timeout; char dump[16*3+16+2]; /* Allow TIMEOUT plus the time needed to actually receive the data bytes: * baudrate/10 bytes per second (8 data bits, start and stop bit) * TODO: use dlbaud if selected. */ - timeout = TIMEOUT + len;//*1000/(skytraq_baud/10); + int timeout = TIMEOUT + len;//*1000/(skytraq_baud/10); /*TODO: timeout gets <0 e.g. when len~=250000 --> 32bit signed int is too small. if (skytraq_baud > 0) timeout = TIMEOUT + (long long int)len*1000*10/(long long int)skytraq_baud; printf("len=%i skytraq_baud=%i timeout=%i\n", len, skytraq_baud, timeout);*/ - rc = gbser_read_wait(serial_handle, (void*)buf, len, timeout); + int rc = gbser_read_wait(serial_handle, (void*)buf, len, timeout); if (rc < 0) { db(1, MYNAME ": rd_buf(): Read error (%d)\n", rc); return res_ERROR; @@ -274,7 +273,6 @@ skytraq_rd_msg(const void* payload, unsigned int len) int errors = 5; /* allow this many errors */ unsigned int c, i, state; signed int rcv_len; - unsigned int calc_cs, rcv_cs; for (i = 0, state = 0; i < RETRIES && state < sizeof(MSG_START); i++) { c = rd_char(&errors); @@ -303,13 +301,13 @@ skytraq_rd_msg(const void* payload, unsigned int len) db(2, "Receiving message with %i bytes of payload (expected >=%i)\n", rcv_len, len); rd_buf((const unsigned char*) payload, MIN(rcv_len, len)); - calc_cs = skytraq_calc_checksum((const unsigned char*) payload, MIN(rcv_len, len)); + unsigned int calc_cs = skytraq_calc_checksum((const unsigned char*) payload, MIN(rcv_len, len)); for (i = 0; i < rcv_len-len; i++) { c = rd_char(&errors); calc_cs ^= c; } - rcv_cs = rd_char(&errors); + unsigned int rcv_cs = rd_char(&errors); if (rcv_cs != calc_cs) { fatal(MYNAME ": Checksum error: got 0x%02x, expected 0x%02x\n", rcv_cs, calc_cs); } @@ -325,8 +323,6 @@ skytraq_rd_msg(const void* payload, unsigned int len) static void skytraq_wr_msg(const uint8_t* payload, int len) { - int cs; - rd_drain(); wr_buf(MSG_START, sizeof(MSG_START)); @@ -334,7 +330,7 @@ skytraq_wr_msg(const uint8_t* payload, int len) wr_char(len & 0x0FF); wr_buf(payload, len); - cs = skytraq_calc_checksum(payload, len); + int cs = skytraq_calc_checksum(payload, len); wr_char(cs); wr_buf(NL, sizeof(NL)); } @@ -397,14 +393,12 @@ skytraq_expect_msg(uint8_t id, const uint8_t* payload, int len) static int skytraq_wr_msg_verify(const uint8_t* payload, int len) { - int rc; - for (int i = 0; i < MSG_RETRIES; i++) { if (i > 0) { db(1, "resending msg (id=0x%02x)...\n", payload[0]); } skytraq_wr_msg(payload, len); - rc = skytraq_expect_ack(payload[0]); + int rc = skytraq_expect_ack(payload[0]); if (rc == res_OK || rc == res_NACK) { return rc; } @@ -433,7 +427,6 @@ skytraq_set_baud(int baud) */ uint8_t MSG_CONFIGURE_SERIAL_PORT[4] = { 0x05, 0x00, 0x00, 0x02 }; - int rc; db(2, "Setting baud rate to %i\n", baud); @@ -463,7 +456,7 @@ skytraq_set_baud(int baud) fatal(MYNAME ": Unsupported baud rate: %ibd\n", baud); } - rc = skytraq_wr_msg_verify(MSG_CONFIGURE_SERIAL_PORT, sizeof(MSG_CONFIGURE_SERIAL_PORT)); + int rc = skytraq_wr_msg_verify(MSG_CONFIGURE_SERIAL_PORT, sizeof(MSG_CONFIGURE_SERIAL_PORT)); if (rc != res_OK) { db(2, "Warning: error setting skytraq device baud rate\n"); return rc; @@ -547,16 +540,14 @@ skytraq_get_log_buffer_status(uint32_t* log_wr_ptr, uint16_t* sectors_free, uint *sectors_free = le_readu16(&MSG_LOG_STATUS_OUTPUT.sectors_free); *sectors_total = le_readu16(&MSG_LOG_STATUS_OUTPUT.sectors_total); - // print logging parameters -- useful, but does this belong here? - unsigned int tmax, tmin, dmax, dmin, vmax, vmin; // unsigned char log_bool, fifo_mode; char* mystatus; - tmax = le_readu32(&MSG_LOG_STATUS_OUTPUT.max_time); - tmin = le_readu32(&MSG_LOG_STATUS_OUTPUT.min_time); - dmax = le_readu32(&MSG_LOG_STATUS_OUTPUT.max_dist); - dmin = le_readu32(&MSG_LOG_STATUS_OUTPUT.min_dist); - vmax = le_readu32(&MSG_LOG_STATUS_OUTPUT.max_speed); - vmin = le_readu32(&MSG_LOG_STATUS_OUTPUT.min_speed); + unsigned int tmax = le_readu32(&MSG_LOG_STATUS_OUTPUT.max_time); + unsigned int tmin = le_readu32(&MSG_LOG_STATUS_OUTPUT.min_time); + unsigned int dmax = le_readu32(&MSG_LOG_STATUS_OUTPUT.max_dist); + unsigned int dmin = le_readu32(&MSG_LOG_STATUS_OUTPUT.min_dist); + unsigned int vmax = le_readu32(&MSG_LOG_STATUS_OUTPUT.max_speed); + unsigned int vmin = le_readu32(&MSG_LOG_STATUS_OUTPUT.min_speed); // log_bool = *(MSG_LOG_STATUS_OUTPUT.datalog_enable); // fifo_mode = *(MSG_LOG_STATUS_OUTPUT.log_fifo_mode); xasprintf(&mystatus, "#logging: tmin=%u, tmax=%u, dmin=%u, dmax=%u, vmin=%u, vmax=%u\n", tmin, tmax, dmin, dmax, vmin, vmax); @@ -659,9 +650,7 @@ struct read_state { static void state_init(struct read_state* pst) { - route_head* track; - - track = route_head_alloc(); + route_head* track = route_head_alloc(); track->rte_name = "SkyTraq tracklog"; track->rte_desc = "SkyTraq GPS tracklog data"; track_add_head(track); @@ -756,7 +745,10 @@ static int process_data_item(struct read_state* pst, const item_frame* pitem, int len) { int res = 0; - double lat, lon, alt, spe; + double lat; + double lon; + double alt; + double spe; unsigned int ts; int poi = 0; full_item f; @@ -1004,8 +996,7 @@ static int skytraq_read_multiple_sectors(int first_sector, unsigned int sector_count, uint8_t* buf) { uint8_t MSG_LOG_READ_MULTI_SECTORS[5] = { 0x1D }; - uint8_t* buf_end_tag; - unsigned int cs, i, read_result; + unsigned int i; if (first_sector < 0 || first_sector > 0xFFFF) { fatal(MYNAME ": Invalid sector number (%i)\n", first_sector); @@ -1018,7 +1009,7 @@ skytraq_read_multiple_sectors(int first_sector, unsigned int sector_count, uint8 db(2, "Reading %i sectors beginning from #%i...\n", sector_count, first_sector); - read_result = skytraq_wr_msg_verify((uint8_t*)&MSG_LOG_READ_MULTI_SECTORS, sizeof(MSG_LOG_READ_MULTI_SECTORS)); + unsigned int read_result = skytraq_wr_msg_verify((uint8_t*)&MSG_LOG_READ_MULTI_SECTORS, sizeof(MSG_LOG_READ_MULTI_SECTORS)); if (read_result != res_OK) { return read_result; } @@ -1029,7 +1020,7 @@ skytraq_read_multiple_sectors(int first_sector, unsigned int sector_count, uint8 } rd_buf(buf+SECTOR_SIZE*sector_count, sizeof(SECTOR_READ_END)+6); - buf_end_tag = buf + SECTOR_SIZE*sector_count; + uint8_t* buf_end_tag = buf + SECTOR_SIZE*sector_count; for (i = 0; i < sizeof(SECTOR_READ_END); i++) { if (buf_end_tag[i] != SECTOR_READ_END[i]) { db(1, MYNAME ": Wrong end tag: got 0x%02x ('%c'), expected 0x%02x ('%c')\n", @@ -1039,7 +1030,7 @@ skytraq_read_multiple_sectors(int first_sector, unsigned int sector_count, uint8 } } - cs = skytraq_calc_checksum(buf, SECTOR_SIZE*sector_count); + unsigned int cs = skytraq_calc_checksum(buf, SECTOR_SIZE*sector_count); if (cs != buf_end_tag[sizeof(SECTOR_READ_END)]) { db(1, MYNAME ": Checksum error while reading sector: got 0x%02x, expected 0x%02x\n", buf_end_tag[sizeof(SECTOR_READ_END)], cs); @@ -1319,8 +1310,6 @@ skytraq_rd_deinit() static void skytraq_read() { - int dlbaud; - if (opt_set_location) { skytraq_set_location(); return; @@ -1331,7 +1320,7 @@ skytraq_read() return; } - dlbaud = atoi(opt_dlbaud); + int dlbaud = atoi(opt_dlbaud); if (dlbaud != 0 && dlbaud != skytraq_baud) { skytraq_set_baud(dlbaud); } @@ -1372,14 +1361,12 @@ static void file_read() { struct read_state st; - int rc, got_bytes; + int got_bytes; int opt_first_sector_val = atoi(opt_first_sector); int opt_last_sector_val = atoi(opt_last_sector); - int sectors_read; - uint8_t* buffer; state_init(&st); - buffer = (uint8_t*) xmalloc(SECTOR_SIZE); + uint8_t* buffer = (uint8_t*) xmalloc(SECTOR_SIZE); if (opt_first_sector_val > 0) { db(4, MYNAME ": Seeking to first-sector index %i\n", opt_first_sector_val*SECTOR_SIZE); @@ -1387,10 +1374,10 @@ file_read() } db(1, MYNAME ": Reading log data from file...\n"); - sectors_read = 0; + int sectors_read = 0; while ((got_bytes = gbfread(buffer, 1, SECTOR_SIZE, file_handle)) > 0) { db(4, MYNAME ": Decoding sector #%i...\n", sectors_read++); - rc = process_data_sector(&st, buffer, got_bytes); + int rc = process_data_sector(&st, buffer, got_bytes); if (opt_last_sector_val < 0) { if (rc < (4096-FULL_ITEM_LEN)) { db(1, MYNAME ": Empty sector encountered, terminating.\n"); @@ -1505,18 +1492,15 @@ static int getPoiByName(char* name) // http://earth-info.nga.mil/GandG/publications/tr8350.2/wgs84fin.pdf static void lla2ecef(double lat, double lng, double alt, double* ecef_x, double* ecef_y, double* ecef_z) { - long double n; long double a = 6378137.0; long double esqr = 6.69437999014e-3; - long double s; - long double llat, llng, lalt; - llat=lat*M_PI/180; - llng=lng*M_PI/180; - lalt=alt; + long double llat = lat*M_PI/180; + long double llng = lng*M_PI/180; + long double lalt = alt; - s=sin(llat); - n = a / sqrt(1 - esqr * s*s); + long double s = sin(llat); + long double n = a / sqrt(1 - esqr * s*s); *ecef_x = (double)((n+lalt) * cos(llat) * cos(llng)); *ecef_y = (double)((n+lalt) * cos(llat) * sin(llng)); @@ -1527,8 +1511,6 @@ static void miniHomer_get_poi() uint8_t MSG_GET_POI[3] = { 0x4D, 0, 0}; uint8_t buf[32]; double lat, lng, alt; - double ecef_x, ecef_y, ecef_z; - Waypoint* wpt; for (unsigned int poi = 0; poi>8)&0xff; @@ -1537,9 +1519,9 @@ static void miniHomer_get_poi() warning(MYNAME ": cannot read poi %d '%s'\n", poi, poinames[poi]); } skytraq_rd_msg(buf, 25); - ecef_x=be_read_double(buf+1); - ecef_y=be_read_double(buf+9); - ecef_z=be_read_double(buf+17); + double ecef_x = be_read_double(buf+1); + double ecef_y = be_read_double(buf+9); + double ecef_z = be_read_double(buf+17); // todo - how to determine not-set POIs ? if (ecef_x < 100.0 && ecef_y < 100.0 && ecef_z < 100.0) { @@ -1547,7 +1529,7 @@ static void miniHomer_get_poi() } else { ECEF_to_LLA(ecef_x, ecef_y, ecef_z, &lat, &lng, &alt); - wpt = new Waypoint; + Waypoint* wpt = new Waypoint; wpt->shortname = QString().sprintf("POI_%s", poinames[poi]); wpt->description = QString().sprintf("miniHomer points to this coordinates if the %s symbol is on", poinames[poi]); wpt->latitude = lat; @@ -1576,12 +1558,11 @@ static int miniHomer_set_poi(uint16_t poinum, const char* opt_poi) 0, 0, 0, 0, 0, 0, 0, 0, //alt (double ecef) 0 // attr (u8, 1-> to flash, 0->ro sram) }; - int n, result; double lat, lng, alt; double ecef_x, ecef_y, ecef_z; - result=0; // result will be 0 if opt_poi isn't set + int result = 0; // result will be 0 if opt_poi isn't set if (opt_poi) { // first check opt_poi if (*opt_poi) { lat=lng=alt=0.0; @@ -1589,7 +1570,7 @@ static int miniHomer_set_poi(uint16_t poinum, const char* opt_poi) * parse format of :[:alt] * we assume at least two elements in the value string */ - n = sscanf(opt_poi, "%lf:%lf:%lf", &lat, &lng, &alt); + int n = sscanf(opt_poi, "%lf:%lf:%lf", &lat, &lng, &alt); if (n >= 2) { db(3, "found %d elems '%s':poi=%s@%d, lat=%f, lng=%f, alt=%f over=%s\n", n, opt_poi, poinames[poinum], poinum, lat, lng, alt); lla2ecef(lat, lng, alt, &ecef_x, &ecef_y, &ecef_z); diff --git a/smplrout.cc b/smplrout.cc index 5aa984da7..c4026f1c1 100644 --- a/smplrout.cc +++ b/smplrout.cc @@ -95,7 +95,7 @@ void SimplifyRouteFilter::routesimple_waypt_pr(const Waypoint* wpt) void SimplifyRouteFilter::compute_xte(struct xte* xte_rec) { const Waypoint* wpt3 = xte_rec->intermed->wpt; - double frac, reslat, reslon; + double reslat, reslon; /* if no previous, this is an endpoint and must be preserved. */ if (!xte_rec->intermed->prev) { xte_rec->distance = HUGEVAL; @@ -129,8 +129,8 @@ void SimplifyRouteFilter::compute_xte(struct xte* xte_rec) } // if timestamps exist, distance to interpolated point if (wpt1->GetCreationTime() != wpt2->GetCreationTime()) { - frac = (double)(wpt3->GetCreationTime().toTime_t() - wpt1->GetCreationTime().toTime_t()) / - (wpt2->GetCreationTime().toTime_t() - wpt1->GetCreationTime().toTime_t()); + double frac = (double)(wpt3->GetCreationTime().toTime_t() - wpt1->GetCreationTime().toTime_t()) / + (wpt2->GetCreationTime().toTime_t() - wpt1->GetCreationTime().toTime_t()); linepart(wpt1->latitude, wpt1->longitude, wpt2->latitude, wpt2->longitude, frac, &reslat, &reslon); diff --git a/stackfilter.cc b/stackfilter.cc index ada7c7307..c1fea560c 100644 --- a/stackfilter.cc +++ b/stackfilter.cc @@ -34,7 +34,6 @@ void StackFilter::process() queue* elem = nullptr; queue* tmp = nullptr; queue tmp_queue; - unsigned int tmp_count; if (opt_push) { tmp_elt = (struct stack_elt*)xmalloc(sizeof(struct stack_elt)); @@ -121,7 +120,7 @@ void StackFilter::process() xfree(tmp); track_restore(&tmp_queue); - tmp_count = waypt_count(); + unsigned int tmp_count = waypt_count(); set_waypt_count(tmp_elt->waypt_ct); tmp_elt->waypt_ct = tmp_count; } diff --git a/stmsdf.cc b/stmsdf.cc index 94f1d068b..f48ffc15d 100644 --- a/stmsdf.cc +++ b/stmsdf.cc @@ -176,9 +176,7 @@ track_qsort_cb(const void* a, const void* b) static void finalize_tracks(void) { - Waypoint** list; queue* elem, *tmp; - int index; route_head* track = nullptr; int trackno = 0; @@ -190,9 +188,9 @@ finalize_tracks(void) return; } - list = (Waypoint**)xmalloc(count * sizeof(*list)); + Waypoint** list = (Waypoint**)xmalloc(count * sizeof(*list)); - index = 0; + int index = 0; QUEUE_FOR_EACH(&trackpts, elem, tmp) { list[index] = (Waypoint*)elem; dequeue(elem); @@ -437,9 +435,6 @@ calculate(const Waypoint* wpt, double* dist, double* speed, double* course, double* asc, double* desc) { if (trkpt_out != nullptr) { - - time_t time; - *course = heading_true_degrees( RAD(trkpt_out->latitude), RAD(trkpt_out->longitude), RAD(wpt->latitude), RAD(wpt->longitude)); @@ -451,7 +446,7 @@ calculate(const Waypoint* wpt, double* dist, double* speed, double* course, *dist = 0; /* calc. diffs on 32- and 64-bit hosts */ } - time = wpt->creation_time.toTime_t() - trkpt_out->GetCreationTime().toTime_t(); + time_t time = wpt->creation_time.toTime_t() - trkpt_out->GetCreationTime().toTime_t(); if (time == 0) { *speed = 0; } else { diff --git a/stmwpp.cc b/stmwpp.cc index 52be78c2a..cdca3bbed 100644 --- a/stmwpp.cc +++ b/stmwpp.cc @@ -77,11 +77,10 @@ stmwpp_rd_deinit(void) static void stmwpp_data_read(void) { - char* buff; int line = 0; what = STM_NOTHING; - buff = gbfgetstr(fin); + char* buff = gbfgetstr(fin); buff = (buff == nullptr) ? (char*) "" : buff; if (case_ignore_strncmp(buff, "Datum,WGS 84,WGS 84,", 20) != 0) { @@ -217,9 +216,8 @@ static void stmwpp_write_double(const double val) { char buff[64]; - char* c; - c = buff + snprintf(buff, sizeof(buff), "%3.7f", val); + char* c = buff + snprintf(buff, sizeof(buff), "%3.7f", val); while (*--c == '0') { *c = '\0'; } @@ -233,14 +231,13 @@ static void stmwpp_waypt_cb(const Waypoint* wpt) { char cdate[16], ctime[16]; - struct tm tm; if (track_index != track_num) { return; } const time_t tt = wpt->GetCreationTime().toTime_t(); - tm = *gmtime(&tt); + struct tm tm = *gmtime(&tt); tm.tm_year += 1900; tm.tm_mon++; diff --git a/subrip.cc b/subrip.cc index da20ca93b..53dbc06fd 100644 --- a/subrip.cc +++ b/subrip.cc @@ -58,8 +58,7 @@ sync_time(time_t arg_gpstime, char* arg_videotime) static void subrip_prevwp_pr(const Waypoint* waypointp) { - QDateTime startdtime, enddtime; - QTime starttime, endtime; + QDateTime enddtime; /* Now that we have the next waypoint, we can write out the subtitle for * the previous one. @@ -75,14 +74,14 @@ subrip_prevwp_pr(const Waypoint* waypointp) gbfprintf(fout, "%d\n", stnum++); /* Writes start and end time for subtitle display to file. */ - startdtime = prevwpp->GetCreationTime().addSecs(-time_offset); + QDateTime startdtime = prevwpp->GetCreationTime().addSecs(-time_offset); if (!waypointp) { enddtime = startdtime.addSecs(1); } else { enddtime = waypointp->GetCreationTime().addSecs(-time_offset); } - starttime = startdtime.toUTC().time(); - endtime = enddtime.toUTC().time(); + QTime starttime = startdtime.toUTC().time(); + QTime endtime = enddtime.toUTC().time(); gbfprintf(fout, "%02d:%02d:%02d,%03d --> %02d:%02d:%02d,%03d\n", starttime.hour(), starttime.minute(), starttime.second(), starttime.msec(), endtime.hour(), endtime.minute(), endtime.second(), endtime.msec()); @@ -198,7 +197,6 @@ static void subrip_wr_init(const QString& fname) { time_t gpstime_t; - struct tm* ptm_gps; stnum = 1; @@ -210,7 +208,7 @@ subrip_wr_init(const QString& fname) if ((opt_gpstime != nullptr) && (opt_gpsdate != nullptr)) { time(&gpstime_t); - ptm_gps = gmtime(&gpstime_t); + struct tm* ptm_gps = gmtime(&gpstime_t); if (opt_gpstime) { sscanf(opt_gpstime, "%2d%2d%2d", &ptm_gps->tm_hour, &ptm_gps->tm_min, &ptm_gps->tm_sec); } diff --git a/swapdata.cc b/swapdata.cc index 25dfa3938..1941215ee 100644 --- a/swapdata.cc +++ b/swapdata.cc @@ -31,9 +31,8 @@ void SwapDataFilter::swapdata_cb(const Waypoint* ref) { Waypoint* wpt = const_cast(ref); - double x; - x = wpt->latitude; + double x = wpt->latitude; wpt->latitude = wpt->longitude; wpt->longitude = x; diff --git a/tef_xml.cc b/tef_xml.cc index 1ec6f8e55..a06201659 100644 --- a/tef_xml.cc +++ b/tef_xml.cc @@ -186,12 +186,11 @@ fix_notes(const QString&, const QString& notes){ static void waypoint_final() { - int via; if (wpt_tmp == nullptr) { return; } - via = wpt_tmp->wpt_flags.fmt_use ; + int via = wpt_tmp->wpt_flags.fmt_use; wpt_tmp->wpt_flags.fmt_use = 0; if (version < 2) { /* keep the old behaviour */ @@ -271,9 +270,8 @@ static double tef_read_comma_float(const QStringRef& value) { QString svalue = value.toString(); - int cidx; - cidx = svalue.indexOf(','); + int cidx = svalue.indexOf(','); if (cidx == -1) { return svalue.toDouble(); } diff --git a/text.cc b/text.cc index 489e6a26a..7f95080a5 100644 --- a/text.cc +++ b/text.cc @@ -100,9 +100,8 @@ text_disp(const Waypoint* wpt) int32_t utmz; double utme, utmn; char utmzc; - char* tmpout1, *tmpout2; + char* tmpout2; char* altout; - fs_xml* fs_gpx; waypoint_count++; @@ -114,7 +113,7 @@ text_disp(const Waypoint* wpt) GPS_Math_WGS84_To_UTM_EN(wpt->latitude, wpt->longitude, &utme, &utmn, &utmz, &utmzc); - tmpout1 = pretty_deg_format(wpt->latitude, wpt->longitude, degformat[2], " ", 0); + char* tmpout1 = pretty_deg_format(wpt->latitude, wpt->longitude, degformat[2], " ", 0); if (wpt->altitude != unknown_alt) { xasprintf(&altout, " alt:%d", (int)((altunits[0]=='f')?METERS_TO_FEET(wpt->altitude):wpt->altitude)); } else { @@ -167,7 +166,7 @@ text_disp(const Waypoint* wpt) gbfputs("\n", file_out); } - fs_gpx = nullptr; + fs_xml* fs_gpx = nullptr; if (includelogs) { fs_gpx = (fs_xml*)fs_chain_find(wpt->fs, FS_GPX); } diff --git a/tiger.cc b/tiger.cc index d7b1fc87b..da562ae69 100644 --- a/tiger.cc +++ b/tiger.cc @@ -159,7 +159,6 @@ data_read() char desc[101]; char icon[101]; char* ibuf; - Waypoint* wpt_tmp; int line = 0; while ((ibuf = gbfgetstr(file_in))) { @@ -168,7 +167,7 @@ data_read() } if (sscanf(ibuf, "%lf,%lf:%100[^:]:%100[^\n]", &lon, &lat, icon, desc)) { - wpt_tmp = new Waypoint; + Waypoint* wpt_tmp = new Waypoint; wpt_tmp->longitude = lon; wpt_tmp->latitude = lat; @@ -263,7 +262,6 @@ dscale(double distance) static void data_write() { - double latsz,lonsz; maxlat = -9999.0; maxlon = -9999.0; minlat = 9999.0; @@ -283,11 +281,9 @@ data_write() waypt_disp_all(tiger_disp); if (genurl) { - gbfile* urlf; - - urlf = gbfopen(genurl, "w", MYNAME); - latsz = fabs(maxlat - minlat); - lonsz = fabs(maxlon - minlon); + gbfile* urlf = gbfopen(genurl, "w", MYNAME); + double latsz = fabs(maxlat - minlat); + double lonsz = fabs(maxlon - minlon); /* * Center the map along X and Y axis the midpoint of diff --git a/tmpro.cc b/tmpro.cc index bd4afe43b..2a58746b7 100644 --- a/tmpro.cc +++ b/tmpro.cc @@ -70,9 +70,6 @@ static void data_read() { char* buff; - char* s; - Waypoint* wpt_tmp; - int i; int linecount = 0; while ((buff = gbfgetstr(file_in))) { @@ -83,13 +80,13 @@ data_read() /* skip the line if it contains "sHyperLink" as it is a header (I hope :) */ if ((strlen(buff)) && (strstr(buff, "sHyperLink") == nullptr)) { - wpt_tmp = new Waypoint; + Waypoint* wpt_tmp = new Waypoint; /* data delimited by tabs, not enclosed in quotes. */ - s = buff; + char* s = buff; s = csv_lineparse(s, "\t", "", linecount); - i = 0; + int i = 0; while (s) { switch (i) { diff --git a/tomtom.cc b/tomtom.cc index 929e2193e..94c0d7c45 100644 --- a/tomtom.cc +++ b/tomtom.cc @@ -154,14 +154,13 @@ check_recsize(int sz) static void data_read() { - int rectype; long recsize; long x; long y; char* desc; Waypoint* wpt_tmp; while (!gbfeof(file_in)) { - rectype = read_char(file_in); + int rectype = read_char(file_in); if (rectype == EOF) { fatal(MYNAME ":Unexpected EOF."); } @@ -362,9 +361,7 @@ static struct blockheader* compute_blocks(struct hdr* start, int count, double minlon, double maxlon, double minlat, double maxlat) { - struct blockheader* newblock; - - newblock = (struct blockheader*)xcalloc(sizeof(*newblock), 1); + struct blockheader* newblock = (struct blockheader*)xcalloc(sizeof(*newblock), 1); newblock->start = start; newblock->count = count; newblock->minlon = minlon; diff --git a/tpg.cc b/tpg.cc index fb0e70328..352028d95 100644 --- a/tpg.cc +++ b/tpg.cc @@ -101,11 +101,9 @@ static void tpg_read() { char buff[MAXTPGSTRINGSIZE + 1]; - double lat, lon, elev; double amt; - short int pointcount; - pointcount = gbfgetint16(tpg_file_in); + short int pointcount = gbfgetint16(tpg_file_in); /* the rest of the header */ gbfread(&buff[0], 19, 1, tpg_file_in); @@ -125,16 +123,16 @@ tpg_read() /* coordinates are in NAD27/CONUS datum */ /* 8 bytes - longitude, sign swapped */ - lon = gbfgetdbl(tpg_file_in); + double lon = gbfgetdbl(tpg_file_in); /* 8 bytes - latitude */ - lat = gbfgetdbl(tpg_file_in); + double lat = gbfgetdbl(tpg_file_in); /* swap sign before we do datum conversions */ lon *= -1.0; /* 2 bytes - elevation in feet */ - elev = FEET_TO_METERS(gbfgetint16(tpg_file_in)); + double elev = FEET_TO_METERS(gbfgetint16(tpg_file_in)); /* convert incoming NAD27/CONUS coordinates to WGS84 */ GPS_Math_Known_Datum_To_WGS84_M( @@ -167,9 +165,8 @@ tpg_waypt_pr(const Waypoint* wpt) { double lon, lat; double amt; - short int elev; char tbuf[64]; - char c,ocount; + char ocount; QString shortname; QString description; int i; @@ -226,10 +223,10 @@ tpg_waypt_pr(const Waypoint* wpt) lon *= -1.0; /* convert meters back to feets */ - elev = (short int) METERS_TO_FEET(wpt->altitude); + short int elev = (short int) METERS_TO_FEET(wpt->altitude); /* 1 bytes stringsize for shortname */ - c = shortname.length(); + char c = shortname.length(); ocount = 0; /* * It's reported the only legal characters are upper case @@ -281,14 +278,13 @@ tpg_waypt_pr(const Waypoint* wpt) static void tpg_write() { - int s; unsigned char header_bytes[] = { 0xFF, 0xFF, 0x01, 0x00, 0x0D, 0x00, 0x43, 0x54, 0x6F, 0x70, 0x6F, 0x57, 0x61, 0x79, 0x70, 0x6F, 0x69, 0x6E, 0x74 }; - s = waypt_count(); + int s = waypt_count(); if (global_opts.synthesize_shortnames) { setshort_length(mkshort_handle, 32); diff --git a/tpo.cc b/tpo.cc index a8a4ff1c8..91d082d9e 100644 --- a/tpo.cc +++ b/tpo.cc @@ -142,12 +142,11 @@ tpo_check_version_string() { unsigned char string_size; - char* string_buffer; const char* v3_id_string = "TOPO! Ver"; /* read the id string */ gbfread(&string_size, 1, 1, tpo_file_in); - string_buffer = (char*) xmalloc(string_size+1); + char* string_buffer = (char*) xmalloc(string_size+1); gbfread(string_buffer, 1, string_size, tpo_file_in); /* terminate the string */ @@ -259,10 +258,9 @@ tpo_read_until_section(const char* section_name, int seek_bytes) static void tpo_read_2_x() { char buff[16]; - short track_count, waypoint_count; /* track count */ - track_count = gbfgetint16(tpo_file_in); + short track_count = gbfgetint16(tpo_file_in); /*fprintf(stderr,"track_count:%d\n", track_count);*/ @@ -306,7 +304,7 @@ static void tpo_read_2_x() gbfread(&buff[0], 1, 8, tpo_file_in); /* number of route points */ - waypoint_count = gbfgetint16(tpo_file_in); + short waypoint_count = gbfgetint16(tpo_file_in); /* allocate temporary memory for the waypoint deltas */ std::vector lat_delta(waypoint_count); @@ -374,9 +372,7 @@ static void tpo_read_2_x() // static int tpo_read_int() { - unsigned char val; - - val = (unsigned char) gbfgetc(tpo_file_in); + unsigned char val = (unsigned char) gbfgetc(tpo_file_in); switch (val) { @@ -415,11 +411,10 @@ static int tpo_read_int() static int tpo_find_block(unsigned int block_desired) { unsigned int block_type; - unsigned int block_offset; // Skip 512 byte fixed-length header - block_offset = 512; + unsigned int block_offset = 512; do { @@ -451,15 +446,10 @@ static int tpo_find_block(unsigned int block_desired) // static Waypoint* tpo_convert_ll(int lat, int lon) { - double latitude; - double longitude; - Waypoint* waypoint_temp; - - - waypoint_temp = new Waypoint; + Waypoint* waypoint_temp = new Waypoint; - latitude = (double)lat / 0x800000; - longitude = (double)lon / 0x800000; + double latitude = (double)lat / 0x800000; + double longitude = (double)lon / 0x800000; //printf("lat: %f\tlon: %f\n", latitude, longitude); @@ -502,7 +492,6 @@ public: // static void tpo_process_tracks() { - unsigned int track_count, track_style_count; const int DEBUG = 0; if (DEBUG) { @@ -514,7 +503,7 @@ static void tpo_process_tracks() return; } // Read the number of track styles. - track_style_count = tpo_read_int(); // 8 bit value + unsigned int track_style_count = tpo_read_int(); // 8 bit value if (DEBUG) { printf("Unpacking %u track styles...\n",track_style_count); @@ -597,7 +586,7 @@ static void tpo_process_tracks() } // Read the number of tracks. Can be 8/16/32-bit value. - track_count = tpo_read_int(); + unsigned int track_count = tpo_read_int(); if (DEBUG) { printf("Total Tracks: %u\n", track_count); @@ -610,35 +599,26 @@ static void tpo_process_tracks() // Read/process each track in the file // for (unsigned ii = 0; ii < track_count; ii++) { - unsigned int line_type; - unsigned int track_style; - unsigned int name_length; - unsigned int track_byte_count; - int llvalid; - unsigned char* buf; - int lonscale; - int latscale; int lat = 0; int lon = 0; - route_head* track_temp; char rgb[7],bgr[7]; // Allocate the track struct - track_temp = route_head_alloc(); + route_head* track_temp = route_head_alloc(); track_add_head(track_temp); //UNKNOWN DATA LENGTH - line_type = tpo_read_int(); // always zero?? + unsigned int line_type = tpo_read_int(); // always zero?? // Can be 8/16/32-bit value (defined in 2012, ignored before then) - track_style = tpo_read_int(); // index into freehand route styles defined in this .tpo file + unsigned int track_style = tpo_read_int(); // index into freehand route styles defined in this .tpo file track_style -= 1; // STARTS AT 1, whereas style arrays start at 0 // Can be 8/16/32-bit value - never used? track_length = tpo_read_int(); //UNKNOWN DATA LENGTH - name_length = tpo_read_int(); + unsigned int name_length = tpo_read_int(); QString track_name; if (name_length) { gbfread(track_name, 1, name_length, tpo_file_in); @@ -682,7 +662,7 @@ static void tpo_process_tracks() track_temp->rte_num = ii + 1; //UNKNOWN DATA LENGTH - track_byte_count = tpo_read_int(); + unsigned int track_byte_count = tpo_read_int(); // Read the number of bytes specified for the track. These // contain scaling factors, long/lat's, and offsets from @@ -692,14 +672,14 @@ static void tpo_process_tracks() // proper place for the next track. // Read the track bytes into a buffer - buf = (unsigned char*) xmalloc(track_byte_count); + unsigned char* buf = (unsigned char*) xmalloc(track_byte_count); gbfread(buf, 1, track_byte_count, tpo_file_in); - latscale=0; - lonscale=0; + int latscale = 0; + int lonscale = 0; // Process the track bytes - llvalid = 0; + int llvalid = 0; for (unsigned int jj = 0; jj < track_byte_count;) { Waypoint* waypoint_temp; @@ -806,10 +786,7 @@ static unsigned int tpo_index_ptr; // static void tpo_process_waypoints() { - unsigned int waypoint_count; - - -//printf("Processing Waypoints...\n"); + //printf("Processing Waypoints...\n"); // Find block 0x0e0000 (GPS-Waypoints) if (tpo_find_block(0x0e0000)) { @@ -817,7 +794,7 @@ static void tpo_process_waypoints() } // Read the number of waypoints. 8/16/32-bit value. - waypoint_count = tpo_read_int(); + unsigned int waypoint_count = tpo_read_int(); //printf("Total Waypoints: %d\n", waypoint_count); @@ -832,14 +809,7 @@ static void tpo_process_waypoints() // Read/process each waypoint in the file for (unsigned int ii = 0; ii < waypoint_count; ii++) { - Waypoint* waypoint_temp; - Waypoint* waypoint_temp2; - unsigned int name_length; - int lat; - int lon; - int altitude; - -//UNKNOWN DATA LENGTH + //UNKNOWN DATA LENGTH (void)tpo_read_int(); // 0x00 //UNKNOWN DATA LENGTH @@ -847,7 +817,7 @@ static void tpo_process_waypoints() //UNKNOWN DATA LENGTH // Fetch name length - name_length = tpo_read_int(); + unsigned int name_length = tpo_read_int(); QString waypoint_name; if (name_length) { gbfread(waypoint_name, 1, name_length, tpo_file_in); @@ -859,17 +829,17 @@ static void tpo_process_waypoints() //UNKNOWN DATA LENGTH (void)tpo_read_int(); - lon = gbfgetint32(tpo_file_in); - lat = gbfgetint32(tpo_file_in); + int lon = gbfgetint32(tpo_file_in); + int lat = gbfgetint32(tpo_file_in); // Allocate space for waypoint and store lat/lon - waypoint_temp = tpo_convert_ll(lat, lon); + Waypoint* waypoint_temp = tpo_convert_ll(lat, lon); // Assign the waypoint name waypoint_temp->shortname = waypoint_name; // Grab the altitude in centimeters - altitude = gbfgetint32(tpo_file_in); + int altitude = gbfgetint32(tpo_file_in); // The original untested check for unknown altitude was for 0xfffd000c (-196596 cm), // but a test case submitted later used 0xffce0000 (-3276800 cm). if (altitude == -3276800) { // Unknown altitude @@ -892,7 +862,7 @@ static void tpo_process_waypoints() // For routes (later), we need a duplicate of each waypoint // indexed by the order we read them in. - waypoint_temp2 = new Waypoint(*waypoint_temp); + Waypoint* waypoint_temp2 = new Waypoint(*waypoint_temp); // Attach the copy to our index tpo_wp_index[tpo_index_ptr++] = waypoint_temp2; @@ -926,10 +896,7 @@ static void tpo_process_waypoints() // static void tpo_process_map_notes() { - unsigned int waypoint_count; - - -//printf("Processing Map Notes...\n"); + //printf("Processing Map Notes...\n"); // Find block 0x090000 (Map Notes) if (tpo_find_block(0x090000)) { @@ -937,7 +904,7 @@ static void tpo_process_map_notes() } // Read the number of waypoints. 8/16/32-bit value. - waypoint_count = tpo_read_int(); + unsigned int waypoint_count = tpo_read_int(); //printf("Elements: %d\n", waypoint_count); @@ -947,21 +914,14 @@ static void tpo_process_map_notes() // Process each waypoint for (unsigned int ii = 0; ii < waypoint_count; ii++) { - int lat; - int lon; - unsigned int name_length; - Waypoint* waypoint_temp; - unsigned int num_bytes; - - -//UNKNOWN DATA LENGTH + //UNKNOWN DATA LENGTH (void)tpo_read_int(); - lon = gbfgetint32(tpo_file_in); - lat = gbfgetint32(tpo_file_in); + int lon = gbfgetint32(tpo_file_in); + int lat = gbfgetint32(tpo_file_in); // Allocate space for waypoint and store lat/lon - waypoint_temp = tpo_convert_ll(lat, lon); + Waypoint* waypoint_temp = tpo_convert_ll(lat, lon); // Assign a generic waypoint name waypoint_temp->shortname = QString("NOTE %1").arg(ii + 1); @@ -977,7 +937,7 @@ static void tpo_process_map_notes() //UNKNOWN DATA LENGTH // Fetch comment length - name_length = tpo_read_int(); + unsigned int name_length = tpo_read_int(); if (name_length) { QString comment; @@ -1016,7 +976,7 @@ static void tpo_process_map_notes() // Number of bytes to skip until next element or end of // block. May be 8/16/32 bits. - num_bytes = tpo_read_int(); + unsigned int num_bytes = tpo_read_int(); //printf("num_bytes: %x\n", num_bytes); for (unsigned int jj = 0; jj < num_bytes; jj++) { (void) gbfgetc(tpo_file_in); // Skip bytes @@ -1041,10 +1001,7 @@ static void tpo_process_map_notes() // static void tpo_process_symbols() { - unsigned int waypoint_count; - - -//printf("Processing Symbols...\n"); + //printf("Processing Symbols...\n"); // Find block 0x040000 (Symbols) if (tpo_find_block(0x040000)) { @@ -1052,7 +1009,7 @@ static void tpo_process_symbols() } // Read the number of waypoints. 8/16/32-bit value. - waypoint_count = tpo_read_int(); + unsigned int waypoint_count = tpo_read_int(); //printf("Elements: %d\n", waypoint_count); @@ -1062,22 +1019,17 @@ static void tpo_process_symbols() // Process each waypoint for (unsigned int ii = 0; ii < waypoint_count; ii++) { - int lat; - int lon; - Waypoint* waypoint_temp; - - -//UNKNOWN DATA LENGTH + //UNKNOWN DATA LENGTH (void)tpo_read_int(); //UNKNOWN DATA LENGTH (void)tpo_read_int(); - lon = gbfgetint32(tpo_file_in); - lat = gbfgetint32(tpo_file_in); + int lon = gbfgetint32(tpo_file_in); + int lat = gbfgetint32(tpo_file_in); // Allocate space for waypoint and store lat/lon - waypoint_temp = tpo_convert_ll(lat, lon); + Waypoint* waypoint_temp = tpo_convert_ll(lat, lon); // Assign a generic waypoint name waypoint_temp->shortname = QString("SYM %1").arg(ii + 1); @@ -1095,10 +1047,7 @@ static void tpo_process_symbols() // static void tpo_process_text_labels() { - unsigned int waypoint_count; - - -//printf("Processing Text Labels...\n"); + //printf("Processing Text Labels...\n"); // Find block 0x080000 (Text Labels) if (tpo_find_block(0x080000)) { @@ -1106,7 +1055,7 @@ static void tpo_process_text_labels() } // Read the number of waypoints. 8/16/32-bit value. - waypoint_count = tpo_read_int(); + unsigned int waypoint_count = tpo_read_int(); //printf("Elements: %d\n", waypoint_count); @@ -1116,23 +1065,17 @@ static void tpo_process_text_labels() // Process each waypoint for (unsigned int ii = 0; ii < waypoint_count; ii++) { - int lat; - int lon; - unsigned int name_length; - Waypoint* waypoint_temp; - - -//UNKNOWN DATA LENGTH + //UNKNOWN DATA LENGTH (void)tpo_read_int(); //UNKNOWN DATA LENGTH (void)tpo_read_int(); - lon = gbfgetint32(tpo_file_in); - lat = gbfgetint32(tpo_file_in); + int lon = gbfgetint32(tpo_file_in); + int lat = gbfgetint32(tpo_file_in); // Allocate space for waypoint and store lat/lon - waypoint_temp = tpo_convert_ll(lat, lon); + Waypoint* waypoint_temp = tpo_convert_ll(lat, lon); // Assign a generic waypoint name waypoint_temp->shortname = QString("TXT %1").arg(ii + 1); @@ -1144,7 +1087,7 @@ static void tpo_process_text_labels() // Fetch comment length //UNKNOWN DATA LENGTH - name_length = tpo_read_int(); + unsigned int name_length = tpo_read_int(); if (name_length) { QString comment; gbfread(comment, 1, name_length, tpo_file_in); @@ -1168,10 +1111,7 @@ static void tpo_process_text_labels() // static void tpo_process_routes() { - unsigned int route_count; - - -//printf("Processing Routes...\n"); + //printf("Processing Routes...\n"); // Find block 0x0f0000 (GPS-Routes) if (tpo_find_block(0x0f0000)) { @@ -1179,7 +1119,7 @@ static void tpo_process_routes() } // Read the number of routes. 8/16/32-bit value - route_count = tpo_read_int(); + unsigned int route_count = tpo_read_int(); //printf("Total Routes: %d\n", route_count); @@ -1190,12 +1130,8 @@ static void tpo_process_routes() // Read/process each route in the file // for (unsigned int ii = 0; ii < route_count; ii++) { - unsigned int waypoint_cnt; - route_head* route_temp; - - // Allocate the route struct - route_temp = route_head_alloc(); + route_head* route_temp = route_head_alloc(); route_add_head(route_temp); //UNKNOWN DATA LENGTH @@ -1228,24 +1164,20 @@ static void tpo_process_routes() // Fetch the number of waypoints in this route. 8/16/32-bit // value. - waypoint_cnt = tpo_read_int(); + unsigned int waypoint_cnt = tpo_read_int(); // Run through the list of waypoints, look up each in our // index, then add the waypoint to this route. // for (unsigned int jj = 0; jj < waypoint_cnt; jj++) { - Waypoint* waypoint_temp; - unsigned int val; - - -//UNKNOWN DATA LENGTH + //UNKNOWN DATA LENGTH // Fetch the index to the waypoint - val = tpo_read_int(); + unsigned int val = tpo_read_int(); //printf("val: %x\t\t", val); // Duplicate a waypoint from our index of waypoints. - waypoint_temp = new Waypoint(*tpo_wp_index[val-1]); + Waypoint* waypoint_temp = new Waypoint(*tpo_wp_index[val-1]); // Add the waypoint to the route route_add_wpt(route_temp, waypoint_temp); @@ -1745,7 +1677,6 @@ static void tpo_track_disp(const Waypoint* waypointp) { double lat, lon, amt, x, y, z; - short lat_delta, lon_delta; /* fprintf(stderr, "%f/%f\n", waypointp->latitude, waypointp->longitude); */ @@ -1781,11 +1712,11 @@ tpo_track_disp(const Waypoint* waypointp) lon *= -1.0; /* longitude delta from first route point */ - lon_delta = (short)((first_track_waypoint_lon - lon) / output_track_lon_scale); + short lon_delta = (short)((first_track_waypoint_lon - lon) / output_track_lon_scale); gbfputint16(lon_delta, tpo_file_out); /* latitude delta from first route point */ - lat_delta = (short)((first_track_waypoint_lat - lat) / output_track_lat_scale); + short lat_delta = (short)((first_track_waypoint_lat - lat) / output_track_lat_scale); gbfputint16(lat_delta, tpo_file_out); /* diff --git a/trackfilter.cc b/trackfilter.cc index 0ac8b4b0a..7a0543e46 100644 --- a/trackfilter.cc +++ b/trackfilter.cc @@ -59,12 +59,12 @@ int TrackFilter::trackfilter_opt_count() int TrackFilter::trackfilter_parse_time_opt(const char* arg) { - time_t t0, t1; int sign = 1; const char* cin = arg; char c; - t0 = t1 = 0; + time_t t0 = 0; + time_t t1 = 0; while ((c = *cin++)) { time_t seconds; @@ -174,8 +174,6 @@ fix_type TrackFilter::trackfilter_parse_fix(int* nsats) void TrackFilter::trackfilter_fill_track_list_cb(const route_head* track) /* callback for track_disp_all */ { - int i; - Waypoint* wpt, *prev; queue* elem, *tmp; if (track->rte_waypt_ct == 0) { @@ -197,13 +195,13 @@ void TrackFilter::trackfilter_fill_track_list_cb(const route_head* track) /* ca track_list[track_ct].track = const_cast(track); - i = 0; - prev = nullptr; + int i = 0; + Waypoint* prev = nullptr; QUEUE_FOR_EACH((queue*)&track->waypoint_list, elem, tmp) { track_pts++; - wpt = (Waypoint*)elem; + Waypoint* wpt = (Waypoint*)elem; if (!wpt->creation_time.isValid()) { timeless_pts++; } @@ -278,12 +276,11 @@ void TrackFilter::trackfilter_pack_init_rte_name(route_head* track, const time_t { if (strchr(opt_title, '%') != nullptr) { struct tm tm; - Waypoint* wpt; if (track->rte_waypt_ct == 0) { tm = *localtime(&default_time); } else { - wpt = (Waypoint*) QUEUE_FIRST((queue*)&track->waypoint_list); + Waypoint* wpt = (Waypoint*) QUEUE_FIRST((queue*)&track->waypoint_list); time_t t = wpt->GetCreationTime().toTime_t(); tm = *localtime(&t); } @@ -321,11 +318,9 @@ void TrackFilter::trackfilter_title() void TrackFilter::trackfilter_pack() { int i, j; - trkflt_t prev; - route_head* master; for (i = 1, j = 0; i < track_ct; i++, j++) { - prev = track_list[j]; + trkflt_t prev = track_list[j]; if (prev.last_time >= track_list[i].first_time) { fatal(MYNAME "-pack: Tracks overlap in time! %s >= %s at %d\n", qPrintable(prev.last_time.toString()), @@ -335,7 +330,7 @@ void TrackFilter::trackfilter_pack() /* we fill up the first track by all other track points */ - master = track_list[0].track; + route_head* master = track_list[0].track; for (i = 1; i < track_ct; i++) { queue* elem, *tmp; @@ -358,20 +353,19 @@ void TrackFilter::trackfilter_pack() void TrackFilter::trackfilter_merge() { - int i, j, dropped; + int i; queue* elem, *tmp; - Waypoint** buff; - Waypoint* prev, *wpt; + Waypoint* wpt; route_head* master = track_list[0].track; if (track_pts-timeless_pts < 1) { return; } - buff = (Waypoint**)xcalloc(track_pts-timeless_pts, sizeof(*buff)); + Waypoint** buff = (Waypoint**)xcalloc(track_pts-timeless_pts, sizeof(*buff)); - j = 0; + int j = 0; for (i = 0; i < track_ct; i++) { /* put all points into temp buffer */ route_head* track = track_list[i].track; QUEUE_FOR_EACH((queue*)&track->waypoint_list, elem, tmp) { @@ -399,8 +393,8 @@ void TrackFilter::trackfilter_merge() qsort(buff, track_pts-timeless_pts, sizeof(*buff), trackfilter_merge_qsort_cb); - dropped = timeless_pts; - prev = nullptr; + int dropped = timeless_pts; + Waypoint* prev = nullptr; for (i = 0; i < track_pts-timeless_pts; i++) { buff[i]->extra_data = nullptr; @@ -426,11 +420,9 @@ void TrackFilter::trackfilter_merge() void TrackFilter::trackfilter_split() { - route_head* curr; route_head* master = track_list[0].track; int count = master->rte_waypt_ct; - Waypoint** buff; Waypoint* wpt; queue* elem, *tmp; int i, j; @@ -540,7 +532,7 @@ void TrackFilter::trackfilter_split() trackfilter_split_init_rte_name(master, track_list[0].first_time); - buff = (Waypoint**) xcalloc(count, sizeof(*buff)); + Waypoint** buff = (Waypoint**) xcalloc(count, sizeof(*buff)); i = 0; QUEUE_FOR_EACH((queue*)&master->waypoint_list, elem, tmp) { @@ -548,7 +540,7 @@ void TrackFilter::trackfilter_split() buff[i++] = wpt; } - curr = nullptr; /* will be set by first new track */ + route_head* curr = nullptr; /* will be set by first new track */ for (i=0, j=1; jwaypoint_list, elem, tmp) { - wpt = (Waypoint*)elem; + Waypoint* wpt = (Waypoint*)elem; wpt->creation_time += delta; } @@ -653,24 +643,21 @@ void TrackFilter::trackfilter_move() void TrackFilter::trackfilter_synth() { queue* elem, *tmp; - Waypoint* wpt; double last_course_lat; double last_course_lon; double last_speed_lat; double last_speed_lon; time_t last_speed_time; - int first; - fix_type fix; int nsats = 0; - fix = trackfilter_parse_fix(&nsats); + fix_type fix = trackfilter_parse_fix(&nsats); for (int i = 0; i < track_ct; i++) { route_head* track = track_list[i].track; - first = 1; + int first = 1; QUEUE_FOR_EACH((queue*)&track->waypoint_list, elem, tmp) { - wpt = (Waypoint*)elem; + Waypoint* wpt = (Waypoint*)elem; if (opt_fix) { wpt->fix = fix; if (wpt->sat == 0) { @@ -734,16 +721,14 @@ void TrackFilter::trackfilter_synth() time_t TrackFilter::trackfilter_range_check(const char* timestr) { - int i; char fmt[20]; char c; - const char* cin; struct tm time; - i = 0; + int i = 0; strncpy(fmt, "00000101000000", sizeof(fmt)); - cin = timestr; + const char* cin = timestr; while ((c = *cin++)) { if (fmt[i] == '\0') { @@ -766,7 +751,6 @@ int TrackFilter::trackfilter_range() /* returns number of track points left aft { time_t start, stop; queue* elem, *tmp; - int dropped, inside = 0; if (opt_start != nullptr) { start = trackfilter_range_check(opt_start); @@ -780,7 +764,8 @@ int TrackFilter::trackfilter_range() /* returns number of track points left aft stop = 0x7FFFFFFF; } - dropped = inside = 0; + int dropped = 0; + int inside = 0; for (int i = 0; i < track_ct; i++) { route_head* track = track_list[i].track; @@ -869,16 +854,13 @@ void TrackFilter::trackfilter_seg2trk() void TrackFilter::trackfilter_trk2seg() { - int first; - route_head* master; - - master = track_list[0].track; + route_head* master = track_list[0].track; for (int i = 1; i < track_ct; i++) { queue* elem, *tmp; route_head* curr = track_list[i].track; - first = 1; + int first = 1; QUEUE_FOR_EACH((queue*)&curr->waypoint_list, elem, tmp) { Waypoint* wpt = (Waypoint*)elem; @@ -905,20 +887,19 @@ void TrackFilter::trackfilter_trk2seg() TrackFilter::faketime_t TrackFilter::trackfilter_faketime_check(const char* timestr) { - int i, j; char fmtstart[20]; char fmtstep[20]; char c; - const char* cin; struct tm time; bool timeparse = true; faketime_t result; result.force = false; - i = j = 0; + int i = 0; + int j = 0; strncpy(fmtstart, "00000101000000", sizeof(fmtstart)); strncpy(fmtstep, "00000000000000", sizeof(fmtstep)); - cin = timestr; + const char* cin = timestr; while ((c = *cin++)) { if (c=='f') { @@ -1110,13 +1091,11 @@ void TrackFilter::process() { RteHdFunctor trackfilter_minpoint_list_cb_f(this, &TrackFilter::trackfilter_minpoint_list_cb); - int opts, something_done; - if (track_ct == 0) { return; /* no track(s), no fun */ } - opts = trackfilter_opt_count(); + int opts = trackfilter_opt_count(); if (opts == 0) { opts = -1; /* flag for do "pack" by default */ } @@ -1214,7 +1193,7 @@ void TrackFilter::process() } } - something_done = 0; + int something_done = 0; if ((opt_pack != nullptr) || (opts == -1)) { /* call our default option */ trackfilter_pack(); diff --git a/transform.cc b/transform.cc index 98ddb4e7b..820628215 100644 --- a/transform.cc +++ b/transform.cc @@ -33,9 +33,7 @@ void TransformFilter::transform_waypoints() { - route_head* rte; - - rte = route_head_alloc(); + route_head* rte = route_head_alloc(); switch (current_target) { case 'R': route_add_head(rte); diff --git a/unicsv.cc b/unicsv.cc index 69c2344eb..9341e6ff3 100644 --- a/unicsv.cc +++ b/unicsv.cc @@ -300,9 +300,8 @@ static arglist_t unicsv_args[] = { static int unicsv_strrcmp(const char* s1, const char* s2) { - int l1, l2; - l1 = strlen(s1); - l2 = strlen(s2); + int l1 = strlen(s1); + int l2 = strlen(s2); if ((l1 - l2) >= 0) { return strcmp(s1 + (l1 - l2), s2); } else { @@ -334,13 +333,13 @@ unicsv_parse_gc_id(const QString& str) static time_t unicsv_parse_date(const char* str, int* consumed) { - int p1, p2, p3, ct; + int p1, p2, p3; char sep[2]; struct tm tm; int lconsumed = 0; memset(&tm, 0, sizeof(tm)); - ct = sscanf(str, "%d%1[-.//]%d%1[-.//]%d%n", &p1, sep, &p2, sep, &p3, &lconsumed); + int ct = sscanf(str, "%d%1[-.//]%d%1[-.//]%d%n", &p1, sep, &p2, sep, &p3, &lconsumed); if (consumed && lconsumed) { *consumed = lconsumed; } @@ -390,23 +389,22 @@ unicsv_parse_date(const char* str, int* consumed) static time_t unicsv_parse_time(const char* str, int* usec, time_t* date) { - int hour, min, ct, sec; + int hour, min, sec; int consumed = 0; double us; char sep[2]; - time_t ldate; /* If we have somethine we're pretty sure is a date, parse that * first, skip over it, and pass that back to the caller) */ - ldate = unicsv_parse_date(str, &consumed); + time_t ldate = unicsv_parse_date(str, &consumed); if (consumed && ldate) { str += consumed; if (date) { *date = ldate; } } - ct = sscanf(str, "%d%1[.://]%d%1[.://]%d%lf", &hour, sep, &min, sep, &sec, &us); + int ct = sscanf(str, "%d%1[.://]%d%1[.://]%d%lf", &hour, sep, &min, sep, &sec, &us); is_fatal(ct < 5, MYNAME ": Could not parse time string (%s).\n", str); if (ct == 6) { *usec = lround((us * 1000000)); @@ -627,7 +625,6 @@ unicsv_rd_deinit() static void unicsv_parse_one_line(char* ibuf) { - int column; int utm_zone = -9999; double utm_easting = 0; double utm_northing = 0; @@ -655,7 +652,7 @@ unicsv_parse_one_line(char* ibuf) wpt->longitude = unicsv_unknown; memset(&ymd, 0, sizeof(ymd)); - column = -1; + int column = -1; QString s; while ((s = csv_lineparse(ibuf, unicsv_fieldsep, "\"", 0)), !s.isNull()) { if (++column >= unicsv_fields_tab.size()) { @@ -1278,10 +1275,8 @@ unicsv_print_data_time(const QDateTime& idt) static void unicsv_waypt_enum_cb(const Waypoint* wpt) { - garmin_fs_t* gmsd; - const QString& shortname = wpt->shortname; - gmsd = GMSD_FIND(wpt); + garmin_fs_t* gmsd = GMSD_FIND(wpt); if (!shortname.isEmpty()) { gb_setbit(&unicsv_outp_flags, fld_shortname); @@ -1432,12 +1427,11 @@ unicsv_waypt_disp_cb(const Waypoint* wpt) { double lat, lon, alt; char* cout = nullptr; - garmin_fs_t* gmsd; const geocache_data* gc_data = nullptr; unicsv_waypt_ct++; QString shortname = wpt->shortname; - gmsd = GMSD_FIND(wpt); + garmin_fs_t* gmsd = GMSD_FIND(wpt); if (unicsv_datum_idx == DATUM_WGS84) { lat = wpt->latitude; @@ -1463,12 +1457,10 @@ unicsv_waypt_disp_cb(const Waypoint* wpt) break; case grid_lat_lon_dms: { - char* sep; - QString tmp; cout = pretty_deg_format(lat, lon, 's', unicsv_fieldsep, 0); - sep = strchr(cout, ','); + char* sep = strchr(cout, ','); *sep = '\0'; - tmp = strenquote(cout, UNICSV_QUOT_CHAR); + QString tmp = strenquote(cout, UNICSV_QUOT_CHAR); gbfprintf(fout, "%s%s", CSTR(tmp), unicsv_fieldsep); tmp = strenquote(sep+1, UNICSV_QUOT_CHAR); gbfputs(tmp, fout); diff --git a/util.cc b/util.cc index 3bcaba266..90d62ac9c 100644 --- a/util.cc +++ b/util.cc @@ -168,14 +168,13 @@ xstrndup(const char* str, size_t sz) { size_t newlen = 0; const char* cin = str; - char* newstr; while ((newlen < sz) && (*cin != '\0')) { newlen++; cin++; } - newstr = (char*) xmalloc(newlen + 1); + char* newstr = (char*) xmalloc(newlen + 1); memcpy(newstr, str, newlen); newstr[newlen] = 0; @@ -215,8 +214,6 @@ XSTRAPPEND(char* src, const char* newd, DEBUG_PARAMS) xstrappend(char* src, const char* newd) #endif { - size_t newsz; - if (!src) { return xxstrdup(newd, file, line); } @@ -224,7 +221,7 @@ xstrappend(char* src, const char* newd) return xxstrdup(src, file, line); } - newsz = strlen(src) + strlen(newd) + 1; + size_t newsz = strlen(src) + strlen(newd) + 1; src = (char*) xxrealloc(src, newsz, file, line); strcat(src, newd); @@ -237,7 +234,6 @@ xstrappend(char* src, const char* newd) FILE* xfopen(const char* fname, const char* type, const char* errtxt) { - FILE* f; int am_writing = strchr(type, 'w') != nullptr; if (fname == nullptr) { @@ -248,7 +244,7 @@ xfopen(const char* fname, const char* type, const char* errtxt) if (0 == strcmp(fname, "-")) { return am_writing ? stdout : stdin; } - f = ufopen(QString::fromUtf8(fname), type); + FILE* f = ufopen(QString::fromUtf8(fname), type); if (nullptr == f) { fatal("%s cannot open '%s' for %s. Error was '%s'.\n", errtxt, fname, @@ -302,10 +298,9 @@ int xasprintf(char** strp, const char* fmt, ...) { va_list args; - int res; va_start(args, fmt); - res = xvasprintf(strp, fmt, args); + int res = xvasprintf(strp, fmt, args); va_end(args); return res; @@ -315,10 +310,9 @@ int xasprintf(QString* strp, const char* fmt, ...) { va_list args; - int res; va_start(args, fmt); char* cstrp; - res = xvasprintf(&cstrp, fmt, args); + int res = xvasprintf(&cstrp, fmt, args); *strp = cstrp; xfree(cstrp); va_end(args); @@ -337,13 +331,12 @@ xvasprintf(char** strp, const char* fmt, va_list ap) # define FIRSTSIZE 1 #endif char* buf = nullptr; - int bufsize; char* newbuf; size_t nextsize = 0; int outsize; va_list args; - bufsize = 0; + int bufsize = 0; for (;;) { if (bufsize == 0) { if ((buf = (char*) xmalloc(FIRSTSIZE)) == nullptr) { @@ -439,13 +432,11 @@ rtrim(char* s) char* lrtrim(char* buff) { - char* c; - if (buff[0] == '\0') { return buff; } - c = buff + strlen(buff); + char* c = buff + strlen(buff); while ((c >= buff) && ((unsigned char)*c <= ' ')) { *c-- = '\0'; } @@ -482,10 +473,8 @@ lrtrim(char* buff) int str_match(const char* str, const char* match) { - const char* m, *s; - - s = str; - m = match; + const char* s = str; + const char* m = match; while (*m || *s) { switch (*m) { @@ -511,8 +500,6 @@ str_match(const char* str, const char* match) } do { - const char* mx, *sx; - while (*s && (*s != *m)) { s++; } @@ -520,8 +507,8 @@ str_match(const char* str, const char* match) return 0; } - sx = s + 1; - mx = m + 1; + const char* sx = s + 1; + const char* mx = m + 1; while (*sx) { if (*mx == '\\') { /* ? escaped ? */ @@ -770,19 +757,17 @@ si_round(double d) time_t mkgmtime(struct tm* t) { - short month, year; - time_t result; static int m_to_d[12] = {0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334}; - month = t->tm_mon; - year = t->tm_year + month / 12 + 1900; + short month = t->tm_mon; + short year = t->tm_year + month / 12 + 1900; month %= 12; if (month < 0) { year -= 1; month += 12; } - result = (year - 1970) * 365 + m_to_d[month]; + time_t result = (year - 1970) * 365 + m_to_d[month]; if (month <= 1) { year -= 1; } @@ -1064,17 +1049,14 @@ be_write_double(void* ptr, double d) /* Magellan and PCX formats use this DDMM.mm format */ double ddmm2degrees(double pcx_val) { - double minutes; - signed int deg; - deg = (signed int)(pcx_val / 100.0); - minutes = (((pcx_val / 100.0) - deg) * 100.0) / 60.0; + signed int deg = (signed int)(pcx_val / 100.0); + double minutes = (((pcx_val / 100.0) - deg) * 100.0) / 60.0; return (double) deg + minutes; } double degrees2ddmm(double deg_val) { - signed int deg; - deg = (signed int) deg_val; + signed int deg = (signed int) deg_val; return (deg * 100.0) + ((deg_val - deg) * 60.0); } @@ -1086,18 +1068,16 @@ double degrees2ddmm(double deg_val) char* strsub(const char* s, const char* search, const char* replace) { - const char* p; int len = strlen(s); int slen = strlen(search); int rlen = strlen(replace); - char* d; - p = strstr(s, search); + const char* p = strstr(s, search); if (!slen || !p) { return nullptr; } - d = (char*) xmalloc(len + rlen + 1); + char* d = (char*) xmalloc(len + rlen + 1); /* Copy first part */ len = p - s; @@ -1119,14 +1099,13 @@ char* gstrsub(const char* s, const char* search, const char* replace) { int ooffs = 0; - char* o; const char* c; const char* src = s; int olen = strlen(src); int slen = strlen(search); int rlen = strlen(replace); - o = (char*) xmalloc(olen + 1); + char* o = (char*) xmalloc(olen + 1); while ((c = strstr(src, search))) { olen += (rlen - slen); @@ -1199,14 +1178,10 @@ rot13(const QString& s) char* convert_human_date_format(const char* human_datef) { - char* result, *cout; - char prev; - int ylen; - - result = (char*) xcalloc((2*strlen(human_datef)) + 1, 1); - cout = result; - prev = '\0'; - ylen = 0; + char* result = (char*) xcalloc((2*strlen(human_datef)) + 1, 1); + char* cout = result; + char prev = '\0'; + int ylen = 0; for (const char* cin = human_datef; *cin; cin++) { char okay = 1; @@ -1267,12 +1242,9 @@ convert_human_date_format(const char* human_datef) char* convert_human_time_format(const char* human_timef) { - char* result, *cout; - char prev; - - result = (char*) xcalloc((2*strlen(human_timef)) + 1, 1); - cout = result; - prev = '\0'; + char* result = (char*) xcalloc((2*strlen(human_timef)) + 1, 1); + char* cout = result; + char prev = '\0'; for (const char* cin = human_timef; *cin; cin++) { int okay = 1; @@ -1363,18 +1335,15 @@ convert_human_time_format(const char* human_timef) char* pretty_deg_format(double lat, double lon, char fmt, const char* sep, int html) { - double latmin, lonmin, latsec, lonsec; - int latint, lonint; - char latsig, lonsig; char* result; - latsig = lat < 0 ? 'S':'N'; - lonsig = lon < 0 ? 'W':'E'; - latint = abs((int) lat); - lonint = abs((int) lon); - latmin = 60.0 * (fabs(lat) - latint); - lonmin = 60.0 * (fabs(lon) - lonint); - latsec = 60.0 * (latmin - floor(latmin)); - lonsec = 60.0 * (lonmin - floor(lonmin)); + char latsig = lat < 0 ? 'S':'N'; + char lonsig = lon < 0 ? 'W':'E'; + int latint = abs((int) lat); + int lonint = abs((int) lon); + double latmin = 60.0 * (fabs(lat) - latint); + double lonmin = 60.0 * (fabs(lon) - lonint); + double latsec = 60.0 * (latmin - floor(latmin)); + double lonsec = 60.0 * (lonmin - floor(lonmin)); if (sep == nullptr) { sep = " "; /* default " " */ } @@ -1406,11 +1375,11 @@ pretty_deg_format(double lat, double lon, char fmt, const char* sep, int html) char* strip_nastyhtml(const QString& in) { - char* returnstr, *sp; - char* lcstr, *lcp; + char* returnstr; + char* lcstr; - sp = returnstr = xstrdup(in); - lcp = lcstr = strlower(xstrdup(in)); + char* sp = returnstr = xstrdup(in); + char* lcp = lcstr = strlower(xstrdup(in)); while (lcp = strstr(lcstr, ""), nullptr != lcp) { sp = returnstr + (lcp - lcstr) ; /* becomes */ @@ -1505,19 +1474,19 @@ strip_html(const utf_string* in) doc.setHtml(in->utfstring); return xstrdup(CSTR(doc.toPlainText().simplified())); #else - char* outstring, *out; - char* incopy, *instr; + char* out; + char* instr; char tag[8]; unsigned short int taglen = 0; - incopy = instr = xstrdup(in->utfstring); + char* incopy = instr = xstrdup(in->utfstring); if (!in->is_html) { return instr; } /* * We only shorten, so just dupe the input buf for space. */ - outstring = out = xstrdup(in->utfstring); + char* outstring = out = xstrdup(in->utfstring); tag[0] = 0; while (*instr) { @@ -1638,19 +1607,20 @@ static char* entitize(const char* str, bool is_html) { - int elen, ecount, nsecount; - entity_types* ep; - const char* cp; - char* p, * tmp, * xstr; + int ecount; + int nsecount; + char* p; + char* tmp; + char* xstr; int bytes = 0; int value = 0; - ep = stdentities; - elen = ecount = nsecount = 0; + entity_types* ep = stdentities; + int elen = ecount = nsecount = 0; /* figure # of entity replacements and additional size. */ while (ep->text) { - cp = str; + const char* cp = str; while ((cp = strstr(cp, ep->text)) != nullptr) { elen += strlen(ep->entity) - strlen(ep->text); ecount++; diff --git a/v900.cc b/v900.cc index ee6e2e57e..0b35ba1d1 100644 --- a/v900.cc +++ b/v900.cc @@ -212,7 +212,6 @@ v900_read() char text[200]; /* used to read the header line, which is normal text */ } line; int lc = 0; - route_head* track; v900_log("%s\n",__func__); @@ -230,14 +229,12 @@ v900_read() v900_log("header line: %s",line.text); v900_log("is_advance_mode=%d\n",is_advanced_mode); - track = route_head_alloc(); + route_head* track = route_head_alloc(); track->rte_name = "V900 tracklog"; track->rte_desc = "V900 GPS tracklog data"; track_add_head(track); while (true) { - Waypoint* wpt; - char c; int bad = 0; int record_len = is_advanced_mode ? sizeof(line.adv) : sizeof(line.bas); if (fread(&line, record_len, 1, fin) != 1) { @@ -295,10 +292,10 @@ v900_read() line.bas.cr = 0; /* null terminate vox field */ } - wpt = new Waypoint; + Waypoint* wpt = new Waypoint; /* lat is a string in the form: 31.768380N */ - c = line.bas.common.latitude_NS; /* N/S */ + char c = line.bas.common.latitude_NS; /* N/S */ assert(c == 'N' || c == 'S'); wpt->latitude = atof(line.bas.common.latitude_num); if (c == 'S') { @@ -318,9 +315,8 @@ v900_read() /* handle date/time fields */ { - int date, time; - date = atoi(line.bas.common.date); - time = atoi(line.bas.common.time); + int date = atoi(line.bas.common.date); + int time = atoi(line.bas.common.time); wpt->SetCreationTime(bintime2utc(date, time)); } @@ -351,13 +347,12 @@ v900_read() track_add_wpt(track, wpt); if (line.bas.common.tag != 'T') { - Waypoint* wpt2; // A 'G' tag appears to be a 'T' tag, but generated on the trailing // edge of a DGPS fix as it decays to an SPS fix. See 1/13/13 email // thread on gpsbabel-misc with Jamie Robertson. assert(line.bas.common.tag == 'C' || line.bas.common.tag == 'G' || line.bas.common.tag == 'V'); - wpt2 = new Waypoint(*wpt); + Waypoint* wpt2 = new Waypoint(*wpt); if (line.bas.common.tag == 'V') { // waypoint with voice recording? char vox_file_name[sizeof(line.adv.vox)+5]; const char* vox = is_advanced_mode ? line.adv.vox : line.bas.vox; diff --git a/vcf.cc b/vcf.cc index 6541ea0bc..aa778564a 100644 --- a/vcf.cc +++ b/vcf.cc @@ -61,17 +61,14 @@ wr_deinit() static void vcf_print_utf(const utf_string* s) { - char* p, *p2, *p3; - char* stripped_html; - if (!s) { return; } - stripped_html = strip_html(s); - p = gstrsub(stripped_html, "\n", "\\n"); - p2 = gstrsub(p, "

", "\\n"); - p3 = gstrsub(p2, ";", "\\;"); + char* stripped_html = strip_html(s); + char* p = gstrsub(stripped_html, "\n", "\\n"); + char* p2 = gstrsub(p, "

", "\\n"); + char* p3 = gstrsub(p2, ";", "\\;"); gbfputs(p3, file_out); xfree(p); xfree(p2); @@ -82,13 +79,11 @@ vcf_print_utf(const utf_string* s) static void vcf_print(const char* s) { - char* p; - if (!s) { return; } - p = gstrsub(s, "\n", "\\n"); + char* p = gstrsub(s, "\n", "\\n"); gbfputs(p, file_out); xfree(p); } @@ -102,10 +97,8 @@ vcf_print(const QString& s) static void vcf_disp(const Waypoint* wpt) { - int latint, lonint; - - lonint = abs((int) wpt->longitude); - latint = abs((int) wpt->latitude); + int lonint = abs((int) wpt->longitude); + int latint = abs((int) wpt->latitude); gbfprintf(file_out, "BEGIN:VCARD\nVERSION:3.0\n"); gbfprintf(file_out, "N:%s;%s;;;\n", CSTRc(wpt->description),CSTRc(wpt->shortname)); diff --git a/vecs.cc b/vecs.cc index b33e01d6a..4c4a947f5 100644 --- a/vecs.cc +++ b/vecs.cc @@ -1395,7 +1395,6 @@ get_option(const char* iarglist, const char* argname) #endif { const size_t arglen = strlen(argname); - char* arglist; char* rval = nullptr; char* argp; @@ -1403,7 +1402,7 @@ get_option(const char* iarglist, const char* argname) return nullptr; } - arglist = xstrdup(iarglist); + char* arglist = xstrdup(iarglist); for (char* arg = arglist; argp = strtok(arg, ","), nullptr != argp; arg = nullptr) { if (0 == case_ignore_strncmp(argp, argname, arglen)) { @@ -1533,10 +1532,9 @@ sort_and_unify_vecs(int* ctp) void disp_vecs() { - vecs_t** svp; int vc; - svp = sort_and_unify_vecs(&vc); + vecs_t** svp = sort_and_unify_vecs(&vc); for (int i = 0; ivec->type == ff_type_internal) { continue; @@ -1559,10 +1557,9 @@ disp_vecs() void disp_vec(const char* vecname) { - vecs_t** svp; int vc; - svp = sort_and_unify_vecs(&vc); + vecs_t** svp = sort_and_unify_vecs(&vc); for (int i = 0; iname, vecname)) { continue; diff --git a/vpl.cc b/vpl.cc index 434e3d6f8..fffca37a3 100644 --- a/vpl.cc +++ b/vpl.cc @@ -173,7 +173,6 @@ vpl_parse_75_sentence(const char* ibuf) int16_t alt, speed_raw; uint16_t hdg_raw; uint8_t sats, hdop_raw, vdop_raw; - Waypoint* waypt; struct tm tm; // The files have DOS line endings (CR/LF) but we don't care, because we @@ -194,7 +193,7 @@ vpl_parse_75_sentence(const char* ibuf) ymd /= 100; tm.tm_year = ymd % 100 + 100; - waypt = new Waypoint; + Waypoint* waypt = new Waypoint; // Lat/Lon are both stored *0xE1000 which we have to divide out // for decimal degrees diff --git a/waypt.cc b/waypt.cc index 825f68b53..ff945a22b 100644 --- a/waypt.cc +++ b/waypt.cc @@ -259,9 +259,8 @@ waypt_compute_bounds(bounds* bounds) foreach(Waypoint* waypointp, waypt_list) { #else queue* elem, *tmp; - Waypoint* waypointp; QUEUE_FOR_EACH(&waypt_head, elem, tmp) { - waypointp = (Waypoint*) elem; + Waypoint* waypointp = (Waypoint*) elem; #endif waypt_add_to_bounds(bounds, waypointp); } @@ -274,10 +273,9 @@ find_waypt_by_name(const QString& name) foreach(Waypoint* waypointp, waypt_list) { #else queue* elem, *tmp; - Waypoint* waypointp; QUEUE_FOR_EACH(&waypt_head, elem, tmp) { - waypointp = (Waypoint*) elem; + Waypoint* waypointp = (Waypoint*) elem; #endif if (waypointp->shortname == name) { return waypointp; @@ -336,11 +334,11 @@ waypt_flush_all() void waypt_backup(signed int* count, queue** head_bak) { - queue* elem, *tmp, *qbackup; + queue* elem, *tmp; Waypoint* wpt; int no = 0; - qbackup = (queue*) xcalloc(1, sizeof(*qbackup)); + queue* qbackup = (queue*) xcalloc(1, sizeof(*qbackup)); QUEUE_INIT(qbackup); #if NEWQ // Why does this code exist? @@ -396,9 +394,7 @@ double gcgeodist(const double lat1, const double lon1, const double lat2, const double lon2) { - double res; - - res = radtometers(gcdist(RAD(lat1), RAD(lon1), RAD(lat2), RAD(lon2))); + double res = radtometers(gcdist(RAD(lat1), RAD(lon1), RAD(lat2), RAD(lon2))); if (res < 0.1) { res = 0; /* calc. diffs on 32- and 64-bit hosts */ } @@ -472,14 +468,12 @@ waypt_distance(const Waypoint* A, const Waypoint* B) double waypt_speed_ex(const Waypoint* A, const Waypoint* B) { - double dist, time; - - dist = waypt_distance_ex(A, B); + double dist = waypt_distance_ex(A, B); if (dist == 0) { return 0; } - time = fabs((double)A->creation_time.msecsTo(B->creation_time)) / 1000.0; + double time = fabs((double)A->creation_time.msecsTo(B->creation_time)) / 1000.0; if (time > 0) { return (dist / time); } else { @@ -495,14 +489,12 @@ waypt_speed_ex(const Waypoint* A, const Waypoint* B) double waypt_speed(const Waypoint* A, const Waypoint* B) { - double dist, time; - - dist = waypt_distance(A, B); + double dist = waypt_distance(A, B); if (dist == 0) { return 0; } - time = fabs((double)A->creation_time.msecsTo(B->creation_time)) / 1000.0; + double time = fabs((double)A->creation_time.msecsTo(B->creation_time)) / 1000.0; if (time > 0) { return (dist / time); } else { @@ -518,14 +510,12 @@ waypt_speed(const Waypoint* A, const Waypoint* B) double waypt_vertical_speed(const Waypoint* A, const Waypoint* B) { - double altitude, time; - - altitude = A->altitude - B->altitude; + double altitude = A->altitude - B->altitude; if (altitude == 0) { return 0; } - time = fabs((double)A->creation_time.msecsTo(B->creation_time)) / 1000.0; + double time = fabs((double)A->creation_time.msecsTo(B->creation_time)) / 1000.0; if (time > 0) { return (altitude / time); } else { @@ -540,19 +530,18 @@ waypt_vertical_speed(const Waypoint* A, const Waypoint* B) double waypt_gradient(const Waypoint* A, const Waypoint* B) { - double dist, altitude, gradient; - dist = waypt_distance(A, B); + double dist = waypt_distance(A, B); if (dist == 0) { return 0; } - altitude = A->altitude - B->altitude; + double altitude = A->altitude - B->altitude; if (altitude == 0 || A->altitude == unknown_alt || B->altitude == unknown_alt) { return 0; } - gradient = (altitude / dist) * 100; + double gradient = (altitude / dist) * 100; return (gradient); } diff --git a/wbt-200.cc b/wbt-200.cc index ca6ce26a1..ff7825777 100644 --- a/wbt-200.cc +++ b/wbt-200.cc @@ -206,10 +206,9 @@ static size_t buf_read(struct buf_head* h, void* data, size_t len) static void buf_extend(struct buf_head* h, size_t amt) { - struct buf_chunk* c; size_t sz = amt + sizeof(struct buf_chunk); - c = (struct buf_chunk*) xmalloc(sz); + struct buf_chunk* c = (struct buf_chunk*) xmalloc(sz); c->next = nullptr; c->size = amt; c->used = 0; @@ -563,16 +562,14 @@ static Waypoint* make_trackpoint(struct read_state* st, double lat, double lon, static int wbt200_data_chunk(struct read_state* st, const void* buf, int fmt) { - uint32_t tim; - double lat, lon, alt; - time_t rtim; + double alt; const char* bp = (const char*) buf; size_t buf_used = fmt_version[fmt].reclen; - tim = le_read32(bp + 0); + uint32_t tim = le_read32(bp + 0); - lat = (double)((int32_t) le_read32(bp + 4)) / 10000000; - lon = (double)((int32_t) le_read32(bp + 8)) / 10000000; + double lat = (double)((int32_t) le_read32(bp + 4)) / 10000000; + double lon = (double)((int32_t) le_read32(bp + 8)) / 10000000; /* Handle extra fields in longer records here. */ if (buf_used >= 16) { @@ -581,7 +578,7 @@ static int wbt200_data_chunk(struct read_state* st, const void* buf, int fmt) alt = unknown_alt; } - rtim = decode_date(tim); + time_t rtim = decode_date(tim); if (lat >= 100) { /* Start new track in the northern hemisphere */ @@ -619,7 +616,6 @@ static int is_valid(struct buf_head* h, int fmt) for (;;) { size_t got = buf_read(h, buf, reclen); - uint32_t tim; /* Don't mind odd bytes at the end - we may * be examining an incomplete dataset. */ @@ -627,7 +623,7 @@ static int is_valid(struct buf_head* h, int fmt) break; } - tim = le_read32(buf + 0); + uint32_t tim = le_read32(buf + 0); if (!check_date(tim)) { return 0; } @@ -706,7 +702,6 @@ static void wbt200_data_read() */ char line_buf[100]; int fmt; - unsigned long count; struct read_state st; state_init(&st); @@ -724,7 +719,7 @@ static void wbt200_data_read() /* Now we're into binary mode */ rd_buf(line_buf, 6); /* six byte header */ - count = le_read16(line_buf + 2) + 1; + unsigned long count = le_read16(line_buf + 2) + 1; if (count == 0x10000) { count = 0; } @@ -797,10 +792,6 @@ static int all_null(const void* buf, const int len) static int wbt201_data_chunk(struct read_state* st, const void* buf) { - uint32_t tim; - uint16_t flags; - double lat, lon, alt; - time_t rtim; const char* bp = (const char*) buf; /* Zero records are skipped */ @@ -808,19 +799,19 @@ static int wbt201_data_chunk(struct read_state* st, const void* buf) return 1; } - flags = le_read16(bp + 0); - tim = le_read32(bp + 2); + uint16_t flags = le_read16(bp + 0); + uint32_t tim = le_read32(bp + 2); if (TK1_END_FLAG == tim) { /* EOF? (TK1 files only as far as I know) */ return 0; } - lat = (double)((int32_t) le_read32(bp + 6)) / 10000000; - lon = (double)((int32_t) le_read32(bp + 10)) / 10000000; - alt = (double)((int16_t) le_read16(bp + 14)); + double lat = (double)((int32_t) le_read32(bp + 6)) / 10000000; + double lon = (double)((int32_t) le_read32(bp + 10)) / 10000000; + double alt = (double)((int16_t) le_read16(bp + 14)); - rtim = decode_date(tim); + time_t rtim = decode_date(tim); if ((flags & WBT201_WAYPOINT) && (global_opts.masked_objective & WPTDATAMASK)) { Waypoint* wpt = make_waypoint(st, lat, lon, alt, rtim); @@ -862,8 +853,7 @@ static int wbt201_read_chunk(struct read_state* st, unsigned pos, unsigned limit { char cmd_buf[30]; char line_buf[100]; - unsigned long cs; - char* lp, *op; + char* op; static const char* cs_prefix = "@AL,CS,"; unsigned want = limit - pos; @@ -893,8 +883,8 @@ static int wbt201_read_chunk(struct read_state* st, unsigned pos, unsigned limit return 0; } - lp = line_buf + strlen(cs_prefix); - cs = strtoul(lp, &op, 16); + char* lp = line_buf + strlen(cs_prefix); + unsigned long cs = strtoul(lp, &op, 16); if (*lp == ',' || *op != ',') { db(2, "Badly formed checksum\n"); return 0; @@ -921,41 +911,25 @@ static void wbt201_data_read() { char line_buf[100]; struct read_state st; - unsigned tries; - - const char* tmp; - - double ver_hw; - double ver_sw; - double ver_fmt; - - unsigned log_addr_start; - unsigned log_addr_end; - unsigned log_area_start; - unsigned log_area_end; - - unsigned wantbytes; - unsigned read_pointer; - unsigned read_limit; /* Read various device information. We don't use much of this yet - * just log_addr_start and log_addr_end - but it's useful to have it * here for debug and documentation purposes. */ - tmp = get_param("@AL,7,1", BUFSPEC(line_buf)); + const char* tmp = get_param("@AL,7,1", BUFSPEC(line_buf)); db(1, "Reading device \"%s\"\n", tmp); - ver_hw = get_param_float("@AL,8,1"); - ver_sw = get_param_float("@AL,8,2"); - ver_fmt = get_param_float("@AL,8,3"); + double ver_hw = get_param_float("@AL,8,1"); + double ver_sw = get_param_float("@AL,8,2"); + double ver_fmt = get_param_float("@AL,8,3"); db(2, "versions: hw=%f, sw=%f, fmt=%f\n", ver_hw, ver_sw, ver_fmt); - log_addr_start = get_param_int("@AL,5,1"); /* we read from here... */ - log_addr_end = get_param_int("@AL,5,2"); /* ...to here, but ... */ - log_area_start = get_param_int("@AL,5,9"); /* ...we need these when ... */ - log_area_end = get_param_int("@AL,5,10"); /* ...the gps wrote more then it fits in memory */ + unsigned log_addr_start = get_param_int("@AL,5,1"); /* we read from here... */ + unsigned log_addr_end = get_param_int("@AL,5,2"); /* ...to here, but ... */ + unsigned log_area_start = get_param_int("@AL,5,9"); /* ...we need these when ... */ + unsigned log_area_end = get_param_int("@AL,5,10"); /* ...the gps wrote more then it fits in memory */ db(2, "Log addr=(%d..%d), area=(%d..%d)\n", log_addr_start, log_addr_end, @@ -963,16 +937,16 @@ static void wbt201_data_read() state_init(&st); - tries = 10; + unsigned tries = 10; /* If the WBT-201 device logs more then the memory can handle it continues to write at the beginning of the memory, * thus overwriting the oldest tracks. In this case log_addr_end is smaller then log_addr_start and we need to read * from log_addr_start to log_area_end and then from log_area_start to log_addr_end. */ - wantbytes = (log_addr_start < log_addr_end) ? log_addr_end - log_addr_start : log_area_end - (log_addr_start - log_addr_end); - read_pointer = log_addr_start; - read_limit = (log_addr_start < log_addr_end) ? log_addr_end : log_area_end; + unsigned wantbytes = (log_addr_start < log_addr_end) ? log_addr_end - log_addr_start : log_area_end - (log_addr_start - log_addr_end); + unsigned read_pointer = log_addr_start; + unsigned read_limit = (log_addr_start < log_addr_end) ? log_addr_end : log_area_end; db(2, "Want %d bytes from device\n", wantbytes); while (wantbytes > 0) { @@ -1005,7 +979,6 @@ static void wbt201_data_read() static void file_read() { char buf[512]; - size_t rc; struct read_state st; int fmt; @@ -1015,7 +988,7 @@ static void file_read() state_init(&st); /* Read the whole file into the buffer */ - rc = fread(buf, 1, sizeof(buf), fl); + size_t rc = fread(buf, 1, sizeof(buf), fl); while (rc != 0) { buf_write(&st.data, buf, rc); rc = fread(buf, 1, sizeof(buf), fl); diff --git a/wintec_tes.cc b/wintec_tes.cc index bd7b368d6..ca2e665be 100644 --- a/wintec_tes.cc +++ b/wintec_tes.cc @@ -60,7 +60,6 @@ wintec_tes_read() track_add_head(trk); while (!gbfeof(fin)) { - Waypoint* wpt; uint16_t flags = gbfgetuint16(fin); uint32_t date = gbfgetuint32(fin); int32_t latitude = gbfgetint32(fin); @@ -68,7 +67,7 @@ wintec_tes_read() int16_t alt = gbfgetint16(fin); // Signed. Meters. (void) flags; // Silence 'unused' warning until we use flags. - wpt = new Waypoint; + Waypoint* wpt = new Waypoint; wpt->latitude = latitude / 1.0e7; wpt->longitude = longitude / 1.0e7; wpt->SetCreationTime(wintec_date_to_time(date)); diff --git a/xcsv.cc b/xcsv.cc index fb2dd951d..7ab6db41f 100644 --- a/xcsv.cc +++ b/xcsv.cc @@ -460,11 +460,10 @@ xcsv_parse_style_buff(const char* sbuff) // FIXME: should not be a static buf. Should not be a raw character // buffer at all! char ibuf[4096]; - size_t i; while (*sbuff) { ibuf[0] = 0; - i = 0; + size_t i = 0; char* ibufp; for (ibufp = ibuf; *sbuff != '\n' && i++ < sizeof(ibuf);) { *ibufp++ = *sbuff++; @@ -481,11 +480,10 @@ static void xcsv_read_style(const char* fname) { char* sbuff; - gbfile* fp; xcsv_file_init(); - fp = gbfopen(fname, "rb", MYNAME); + gbfile* fp = gbfopen(fname, "rb", MYNAME); while ((sbuff = gbfgetstr(fp))) { sbuff = lrtrim(sbuff); xcsv_parse_style_line(sbuff); diff --git a/xmlgeneric.cc b/xmlgeneric.cc index 3b61370d3..e3094cf52 100644 --- a/xmlgeneric.cc +++ b/xmlgeneric.cc @@ -59,8 +59,7 @@ static QTextCodec* codec = utf8_codec; // Qt has no vanilla ASCII encoding =( xg_callback* xml_tbl_lookup(const QString& tag, xg_cb_type cb_type) { - xg_tag_mapping* tm; - for (tm = xg_tag_tbl; tm->tag_cb != nullptr; tm++) { + for (xg_tag_mapping* tm = xg_tag_tbl; tm->tag_cb != nullptr; tm++) { if (str_match(CSTR(tag), tm->tag_name) && (cb_type == tm->cb_type)) { return tm->tag_cb; } diff --git a/xmltag.cc b/xmltag.cc index c17916a9a..e23b7e203 100644 --- a/xmltag.cc +++ b/xmltag.cc @@ -29,14 +29,12 @@ static void free_xml_tag(xml_tag* tag) { - char** ap; - while (tag) { if (tag->child) { free_gpx_extras(tag->child); } if (tag->attributes) { - ap = tag->attributes; + char** ap = tag->attributes; while (*ap) { xfree(*ap++); -- 2.30.2